C# Not letting me use numbers?

When I try using the command AddForce, the script isn’t reacting to the numbers I put in the () after. If I am not mistaken, the numbers within the parenthesis will change color when all is running smoothly. I may be formatting this incorrectly, but when I try using the command

if (Input.GetKey(“w”))
{
rb.AddForce(x: 0, y: 0, z: 500*Time.deltaTime);
}
it doesn’t work after saving the code and reentering the game to test it. I’m not sure if this is a problem with the input, code or script but any help is welcome.

@Atlas754

Try this - Pressing w should make a default cube with attached rigidbody component roll on the floor (if it has collider):

if (Input.GetKey(KeyCode.W))
{
    rb.AddForce(0f, 0, 10f, ForceMode.Force);
}

I bet your issue is with at least the delta time, you might be multiplying your force to be a really small number.

This is at least part of the problem.

  • Do your physics updates in FixedUpdate()
  • Add the force you want (in Newtons) and the time interval will be handled for you

I’m thinking also part of the problem was the lowercase "w", but @eses fixed that above by using the KeyCode.W value.