Answers for "unity how to add force"

C#
2

unity how to add force

public Rigidbody rb;

if(Input.GetKey(KeyCode.W))
{
	rb.AddForce(100, 0, 0);
}
Posted by: Guest on December-13-2020
7

unity rigidbody addforce

rb = GetComponent<Rigidbody>();
rb.AddForce(new Vector3(1.5f,1.5f,1.5f));
Posted by: Guest on February-15-2020
0

how to add a force to an object unity

private Rigidbody2D rb;
public Vector2 direction;
public float force;

void Start()
{
	rb = GetComponent<Rigidbody2D>();
    rb.AddForce(direction * force, ForceMode2D.Impulse);
    //rb.AddForce(--pass in Vector--, --can pass in ForceMode--);
}
Posted by: Guest on April-11-2021

Code answers related to "unity how to add force"

C# Answers by Framework

Browse Popular Code Answers by Language