0
\$\begingroup\$

The "Car" in question is a plane. The question is pretty self explanatory.

Here's the Car in the Hierarchy:

"Car" object with five children, all point lights.

Here's the car in the inspector:

Unity Inspector

And here's the PlayerMovement script:

using UnityEngine; public class PlayerMovement : MonoBehaviour { // -------------------------------- // References // -------------------------------- public Rigidbody rb; // -------------------------------- public float force = 500f; void FixedUpdate() { if (Input.GetKey("w") || Input.GetKey("up")) { Debug.Log("Foreward"); rb.AddForce(0, 0, force * Time.deltaTime); } if (Input.GetKey("a") || Input.GetKey("left")) { rb.AddForce(-force * Time.deltaTime, 0, 0); } if (Input.GetKey("s") || Input.GetKey("down")) { rb.AddForce(0, 0, -force * Time.deltaTime); } if (Input.GetKey("d") || Input.GetKey("right")) { rb.AddForce(force * Time.deltaTime, 0, 0); } } } 

It does show the "Foreward" log when I press W or up arrow, so I know that's working.

(Side note: I know this won't get me actual car physics, I'm just trying to make sure I can move the car at all first)

\$\endgroup\$
4
  • 1
    \$\begingroup\$ You don't want to multiply a force by deltaTime, otherwise you get an impulse, which is not what you're telling the Rigidbody to expect. That could be reducing the magnitude enough that it doesn't move. The other thing that stands out to me is using a Plane for your mesh — a flat plane might not be generating a valid inertia tensor, or it might be penetrating and locking into whatever surface the car is sitting on. Does changing either of those things result in any different behaviour? \$\endgroup\$ Commented Oct 19 at 13:57
  • \$\begingroup\$ Removing ` * Time.deltaTime` didn't help. I changed the mesh renderer and collider to cube instead of plane and that didn't help either. I also tried attaching the script to a default cube without changing any of it's settings, that didn't work either. I'm starting to think it might be an issue in the project settings? \$\endgroup\$ Commented Oct 19 at 21:59
  • \$\begingroup\$ You could uncheck all the freeze modifiers and see if your model is orientated correctly or if the freeze is partially at fault. \$\endgroup\$ Commented Oct 22 at 13:40
  • \$\begingroup\$ I aleady tried that, still nothing. \$\endgroup\$ Commented Oct 22 at 20:16

2 Answers 2

1
\$\begingroup\$

GameObject SDK was set to None, fixed by changing it to PhysX

\$\endgroup\$
-1
\$\begingroup\$

try not multiplying addForce by Time.deltaTime.

\$\endgroup\$
2
  • \$\begingroup\$ If this were the problem, then OP would just see much slower movement than they expect, but not no movement at all. \$\endgroup\$ Commented Oct 21 at 10:26
  • \$\begingroup\$ It's not strictly guaranteed that a small force will lead to slow movement. Below a certain threshold, the velocity imparted by the force can get clamped to zero rather than have a chance to accumulate — so this was a possible fix, even if not a sure thing. That's why I asked about it in my comment above, to see if that would have an effect. \$\endgroup\$ Commented Oct 21 at 10:43

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.