• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by user-4347 (google) · Oct 22, 2010 at 02:44 AM · camerapositionvariableenemy

how to put like a camera on the enemy so he can see you only in a specific angle?

In my game the enemy has a script that check the position 25 far away from the enemy making a circle around him. I make and point 12 m away from the enemy. That works but not to well so I want to know a way to put the enemy like having a camera so that way he can detect some one in that angle then only in some distance the enemy can see you and if its posible put a var certainty that the enemy when you are closer he has more certainty and when you are far he has lower certainty that you are there.

Please if someone can help me I would greatly appreciate it. :)

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Adam Rademacher · Oct 22, 2010 at 03:44 AM

One would typically use a Vector3.Dot solution for this. Dot products compare two vectors and determine the directions they are facing in. Subtract the player position from the enemy position to get the facing vector (this is the vector between the enemy and the player), then take a Dot product to determine how close the enemy is to matching that direction.

The script reference on Vector3.Dot is pretty good and has an example that fits your needs.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image user-4347 (google) · Oct 22, 2010 at 08:58 PM 0
Share

but if I want to have a specif angle to see what I have to do and also what I have to do with the variable certainty

avatar image Adam Rademacher · Oct 23, 2010 at 03:42 AM 0
Share

You'll have to play with numbers a little bit, I suspect. If the Dot product = 1, the enemy is facing directly at the player...if the dot product is 0, the enemy is perpendicular, and if it is -1 they are facing away from the player. So a dot product of .5 would be about a 90 degree "field of view" if you want to think of it (half way to a full perpendicular on each side).

avatar image Owen-Reynolds · May 10, 2011 at 05:15 AM 0
Share

The dot product is the cosin of the angle between them. So if you want 25 degrees, cos(25) is about 0.9. So check Dot(enemy.transform.forward, player-enemy) > 0.9 (really is a greater than, since 1 is facing and lower is more turned away.)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Scripting Issue With Top Down Mouse Movement 1 Answer

Adding y position? 4 Answers

Limiting a distance variable 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Simple enemy kill count 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges