- Home /
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);
}
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.
Answer by dumyY995 · Aug 26, 2011 at 09:12 PM
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 ;)
Your answer
Follow this Question
Related Questions
Velocity powered rigidbody on a moving platform without parenting. 3 Answers
Unable to Apply External Forces to my Rigidbody 0 Answers
Rigid body enemy 1 Answer
Rigidbody Enemy and Collisions 2 Answers