Answers for "unity addforce"

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
6

how to make rb.addforce 2d

public Rigidbody rb; //make reference in Unity Inspector

public float SpeedX = 0.1f;
public float SpeedY = 0.5f;

rb.AddForce(new Vector2(SpeedX, SpeedY));
Posted by: Guest on June-24-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
1

rb.addforce c#

rb.AddForce(0, 0, 5 * Time.deltaTime);

// Time.deltaTime is optional ( Make sure that "T" is caps)
Posted by: Guest on December-06-2020
1

unity c# addforce

public class Example : MonoBehaviour
{
    Rigidbody m_Rigidbody;
    public float m_Thrust = 20f;

    void Start()
    {
        //Fetch the Rigidbody from the GameObject with this script attached
        m_Rigidbody = GetComponent<Rigidbody>();
    }

    void FixedUpdate()
    {
        if (Input.GetButton("Jump"))
        {
            //Apply a force to this Rigidbody in direction of this GameObjects up axis
            m_Rigidbody.AddForce(transform.up * m_Thrust);
        }
    }
}
Posted by: Guest on July-17-2021
0

unity addforce

m_Rigidbody.AddForce(transform.up * m_Thrust);

//rigidbodyToApplyForceTo.AddForce(Direction*Force);
Posted by: Guest on July-31-2021

C# Answers by Framework

Browse Popular Code Answers by Language