Answers for "how to add a force to an object unity"

C#
11

Rigidbody.addforce

using UnityEngine;public class ExampleClass : MonoBehaviour
{
    public float thrust = 1.0f;
    public Rigidbody rb;    void Start()
    {
        rb = GetComponent<Rigidbody>();
        rb.AddForce(0, 0, thrust, ForceMode.Impulse);
    }
}
Posted by: Guest on February-09-2020
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 "how to add a force to an object unity"

C# Answers by Framework

Browse Popular Code Answers by Language