x


Rigidbody enemy Forcemode.VelocityChange

Hello there, I am trying to make a simple enemy that looks and chases the player with a constant velocity using Rigidbody ForceMode.VelocityChange, at the begining it works well but for some reason the enemy follows another direction, what am I doing wrong?!

ex:

var velo = 1.0;

function FixedUpdate () {

   var Player = gameObject.FindWithTag("Player").transform;

   transform.LookAt(Vector3(Player.position.x,transform.position.y,Player.position.z)); 
   rigidbody.AddRelativeForce(transform.forward * velo, ForceMode.VelocityChange);

}
more ▼

asked Jun 22 '11 at 08:48 PM

Fubiou gravatar image

Fubiou
30 12 12 15

I'm not sure if this'll help, but try changing transform.forward to Vector3.forward. AddRelativeForce already converts the supplied Vector3 to local coordinates and supplying it with a Vector3 already containing local coordinates (i.e., Transform.forward) might be producing unintended output.

Jun 22 '11 at 09:02 PM Dreamblur
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

try using transform.LookAt(Player); instead of that long line alsi use Vector3.forward instead of transform.forward (though it might not make a difference)

the script would be: var velo : float = 1.0;

function FixedUpdate () 
{
   var player = gameObject.FindWithTag("Player").transform;

   transform.LookAt(player); 
   rigidbody.AddRelativeForce(Vector3.forward * velo, ForceMode.VelocityChange);

}

If this won't work tell me ;)

more ▼

answered Aug 26 '11 at 09:12 PM

dumyY995 gravatar image

dumyY995
1 1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1790
x653
x318
x32
x9

asked: Jun 22 '11 at 08:48 PM

Seen: 1181 times

Last Updated: Aug 26 '11 at 09:13 PM