Reputation: 148
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public Rigidbody rb;
// Update is called once per frame
void fixedUpdate()
{
rb.AddForce(0, 0, 2000 * Time.deltaTime);
}
}
I am trying to make my cube go forward but it isn't moving forward. I am using the community version of visual studio 2019.
Upvotes: 0
Views: 48
Reputation: 4561
Check that yo attach the rb
in the editor or with code as indicated in the documentation. Check code snippet below. Also you may want to try a bigger forca than 2000 * Time.deltaTime
. Time.deltaTime
is a small value. Check here. Try a bigger value, and check that the mass of the rigidbody is not very big so that the force is big enough to move the body.
using UnityEngine;
public class ExampleClass : MonoBehaviour
{
public float thrust = 1.0f;
public Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
rb.AddForce(transform.forward * thrust);
}
}
Upvotes: 1