I need some help because there r no error messages and nothing happens I’m trying to make the block move
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public Rigidbody rb;
// Start is called before the first frame update
void Start()
{
rb.AddForce(0, 200, 500);
}
// Update is called once per frame
void Update()
{
}
}
that’s the code I used
- Use code tags when posting code
- Are you sure the script is attached?
- Is the rigidbody active (“is kinematic” should be unchecked)?
- Try adding this line to Update to make sure it’s being executed:
Debug.Log("We are running", this);
It should spit out a bunch of messages in the console with this text, and clicking on one of them will take you to the script that posted it.
4) don’t use physics code in Update() - use FixedUpdate() instead. (but this is a minor thing; the object would still move, it’ll just move at an inconsistent speed that varies based on your fps)
1 Like
i put that code in and the error message popped up again
What do you mean again? You said there was no error message before.
What error? Copy and paste it.
And put your code in code tags. The error message will probably have a line number and code tags will help find it.
1 Like
You add a force but you don’t tell unity of what mode I would recommend you look up the scripting Api of AddForce and look what forceMode you need also you should put you Variables in a new Vector3
Here you have a little exsample:
void Start()
{
rb. AddForce(new Vector3(0, 200, 500), ForceMode.Impulse);
}