Rigidbody.AddForce moves in a curve
When the player presses a button, an object "VacuumRange" in activated. When items with the Vacuumable script touch "VacuumRange", they should move in a straight line towards the player. However, the objects always move with a slight curve, although there (should be) no other forces than gravity in the Scene. The ground is flat as well. Does anyone know what it could be? Here is my code:
public class Vacuumable : MonoBehaviour
{
public float suckForce = 25f;
public RigidbodyConstraints rigidbodyConstraints;
public GameObject player;
private void OnTriggerStay(Collider other)
{
if (other.gameObject.tag == "Suck")
{
transform.LookAt(player.transform);
GetComponent<Rigidbody>().AddForce(player.transform.position - transform.position * suckForce * Time.deltaTime);
Debug.DrawLine(transform.position, player.transform.position);
}
}
}
Comment
Best Answer
Answer by BluezamX · Nov 11, 2019 at 02:20 PM
Forgot the brackets around "player.transform.position - transform.position". The line should be GetComponent().AddForce((player.transform.position - transform.position) suckForce Time.deltaTime);