- Home /
how to move an object towards way position only ?
i wanna move some enemy objects toward the player object , but the enemy objects got a bouncing physics so if i moved the enemies to ward the player with the Vector3.MoveTowards it will prevent them from bouncing so i need to move the enemies to the y position of the player only.
and thanks ^ ^
using your Vector3.$$anonymous$$oveTowards() as a variable and then using RigidBody.AddForce(0f, V3$$anonymous$$T.y, 0f);
can't get it here is my code : see and tell what to change
public class CameraFollower : $$anonymous$$onoBehaviour {
public GameObject thePlayer;
private Vector3 offset;
private Rigidbody rb;
void Start () {
offset = transform.position - thePlayer.transform.position;
rb = GetComponent<Rigidbody>();
}
void Update () {
transform.position = thePlayer.transform.position + offset;
rb.constraints = RigidbodyConstraints.FreezePositionY;
}
}
Your answer
Follow this Question
Related Questions
Cinema 4d to unity (Transform/position) 1 Answer
C# move y position of object not working 2 Answers
Copy position from one object to another on one axis 0 Answers
Global transform position and scale for gameObject 0 Answers
Help! I want to make a following camera but in with Y position is constant ? 2 Answers