Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Create with Code - Prototype 1

The games I did as going through Unity's Create with Code online Tutorials · By nynox

Car movement

A topic by Vlad D. created Apr 04, 2020 Views: 479 Replies: 3
Viewing posts 1 to 2
(+2)

Good implementation. But the car moves back and forth with respect to the global coordinate system. If you use the AddForce method to move forward, try replacing it with AddRelativeForce ;)

Developer

Oh... you're right. I did use AddRelativeForce... but I imagine that while debugging the initial "stuckness" of the car I changed it to AddForce and never back. Thank you.

Did you also have this issue of the car being stuck at first - video? Any solutions for that?

(3 edits) (+2)

I just set the high "Horse Power" (25000). For this course, this is an acceptable solution.  I was interested in this question and I found a good video demonstrating the implementation of the car.


As a quick fix, I used WheelCollider.motorTorque:

// Remove force from the car
// playerRb.AddRelativeForce(Vector3.forward * horsePower * forwardInput);
// Add motor torque to the wheels
foreach (var wheel in wheels)
{
    wheel.motorTorque = horsePower * forwardInput;
}

This gives a more correct behavior to the car.

Sorry for my English, I use Google Translate :)

Developer (1 edit)

Great job man! I was not in the mood then to look for other solutions, but this is great. And it makes so much sense... if you use Wheel Colliders to add torque to the wheels instead of Force to the car.

Kudos to you for this! Thank you!

I added your suggestion and reference to the YouTube video and my original comment on the Unity course

You deserve the reference.