- Home /
Question by
elproue · Jan 27 at 01:06 PM ·
rigidbody.addforcefollow playerrigidbody.velocityrigidbody physics
How to move Enemy Gameobject with Rigidbody force/velocity to follow Player?
I use the script below to make Enemy GameObject follow Player:
public Transform target;
public float speed;
Rigidbody rb;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void FixedUpdate()
{
Vector3 pos = Vector3.MoveTowards(transform.position, target.position, speed *
Time.deltaTime);
rb.MovePosition(pos);
transform.LookAt(target);
}
But I want them to move using Rigidbody velocity/force. There are Rigidbody objects placed in Scene. On contact Enemy goes through them but instead I want them to push those objects forward or away while following Player.
Comment
Your answer
Follow this Question
Related Questions
Rigidbody physics; forces doesnt move gameobject in a desired way 1 Answer
How to limit only the Rigidbody.velocity from player input? 1 Answer
Do rigid bodies with force add force to other objects? 0 Answers
How to make RigidBody's movement using fixed movement/velocity and other forces all together? 3 Answers
VR Sword Physics, how to add force or velocity to the sword for impact when it hits an object 1 Answer