I'm programming a script where force would be applied in the transform.forward direction once a ray hit another game object. The problem is that transform.forward keeps going backwards, even though the arrow goes the opposite way.
In addition, I'm having the objects rotate to face the player, but it only moves on the world's Z axis instead of the direction it's facing.
Any solutions?
if (Physics.Raycast (transform.position, fwd, hit, 100) && hit.transform.gameObject.tag == "Player"){
print ("Hit the player");
Debug.DrawLine (transform.position, hit.point);
Chase();
}
function Chase(){
var rotate = Quaternion.LookRotation(player.position - transform.position, Vector3.up);
transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * Damp);
rigidbody.AddRelativeForce(transform.forward * 12);
}