|
Im trying to get an enemy to detect where the player is but at the same time restricting his vision to a cone from his eyes and forward. The cone is an invisible object which should detect collisions using OnCollisionEnter. When collision is detected, it should use a Raycast to see if the object is in sight (and not behind a wall that the cone is penetrating). This is my code so far, and after messing with it for an hour or two now I cant figure out why the detection isnt made.
The script is attached to the cone-object, which is a child of the enemy-object. For testing Ive used a unity-created cylinder instead of a cone, and unchecked Mesh Renderer. It will still prohibit me from moving trough it, though, so I havent solved that issue yet. How? The player-objects name is "FPS". Any suggestions? Thanks, Daniel
(comments are locked)
|
|
You should use a trigger for the cone, and OnTriggerStay() for the raycast code. If the player is a CharacterController, it will also need a kinematic rigidbody attached with some kind of primitive collider in order to interact with the trigger (see the docs about colliders and interaction). Thanks, using trigger worked better :) I ended up using this code: [code] var int_HitRadiusDistance = 20; function OnTriggerEnter (other : Collider) {
} [/code] I will probably exchange the check for FPS and Player with a trigger object, so I can just drag the player-object to the script. I tried putting it on a cylinder, which had the following characteristics: 1) Transform (of course), 2) Mesh Filter, 3) Collider (Is Trigger), 4) Rigid body (not use gravity) The player should have a collider as well. Well, thats about it - now for the attack-code :P
Jan 22 '10 at 02:56 AM
Daniel 1
Thanks for posting your findings Daniel - and thanks for your answer Eric5h5 - between the two of you I was pointed in the right direction to fix an issue that's been hounding me for months... Much thanks!
Apr 01 '11 at 02:30 PM
Brian 7
(comments are locked)
|
