Hello, I am new to unity and was the following beginner game tutorial videos from Brackeys and everything was going absolutely fine until I hit a brick wall from no where. Just yesterday, my cube was moving perfectly and it was such a great feeling but today I ran my game without changing anything and it just won’t move. I have no idea why and I have been trying to solve this problem for almost 5 hours with no luck. This is my rigidbody and the force and sideways force I am applying to my cube:


This is my player movement code:
using UnityEngine;
public class PlayerMovement2 : MonoBehaviour
{
public Rigidbody rb;
public float forwardForce = 2000f;
public float sidewaysForce = 100f;
// Update is called once per frame
//Fixedupdate is for unity physics, update is for anything else that's not in the start() and does not include physics
void Update()
{
//add a forward force
rb.AddForce(0,0, forwardForce * Time.deltaTime);
if (Input.GetKey("d")) {
rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
if (Input.GetKey("a")) {
rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
}
}
I would really like to know the problem here and how to solve it.
Is the
– Llama_w_2Lspublic Rigidbody rbset to the correct rigidbody in your scene? It should be the rigidbody of your player, but judging by the name of it, it's set to player1. Should there be two player objects in your scene? (as well as two player movement scripts). ---------- Another helpful thing would be to debugif (Input.GetKey("d"))is called properly. So you could add a Debug.Log("d was pressed") in that if statement, just to see if it isn't a problem with your key setup. (unlikely). @sneake