Need a vehicle movement expert!

Post Reply
User avatar
Andrey01
Member
Posts: 2579
Joined: Wed Oct 19, 2016 15:18
GitHub: Andrey2470T
In-game: Andrey01
Location: Russia, Moscow

Need a vehicle movement expert!

by Andrey01 » Post

I`m making a second version of my vehicles mod and I would need an expert who probably already made similar mod sometime in the past and who could find out why vehicle movement works quite incorrectly in my case. If you press forward, vehicle will go with constant velocity and only after a while abruptly stop. Or if you press backward, in such case vehicle will very slow accelerate with insignificant jerks and after you release the key vehicle will start to accelerate as expected and abruptly stop. Also, the vehicle actually can not stop, it just vibrates around null velocity. My algorithm in on_step function:
  • 1. Specify a direction of vehicle movement and set resulted value to self.move_dir ('1' if vehicle moves forward, '-1' if vehicle moves backward, '0' if velocity is null).
  • 2. Specify a direction of traction force of vehicle. Signs of resulted values coincides to self.move_dir`s ones and set to self.tracf ('1' if 'up' key pressed, '-1' if 'down' pressed, '0' if otherwise).
  • 3. Check if velocity vector length is between 0 and 0.4, set self.move_dir to null.
  • 4. Calculate a 2d vector of the traction force.
  • 5. Calculate friction factor of surfaces of those nodes which are under each of four vehicle wheels and find out a maximum one of them.
  • 6. Calculate an unit vector of velocity.
  • 7. Calculate a friction force and its vector by multiplying the unit one by the friciton force.
  • 8. Calculate resistance force of air and its vector doing it as in the previous step.
  • 9. Add all those vectors (traction force, surface friction force and air resistance force) and divide by vehicle mass.
  • 10. Set resulted acceleration.


Additionally, calculate rotation of wheels in the same functon:
  • 11. Calculate an angle velocity by dividing velocity vector length by wheel radius and set it in self.object:set_rotation() as 'x'.
Is that correct algorithm?

Download for testing: https://github.com/Andrey2470T/adv_vehicles2

User avatar
Andrey01
Member
Posts: 2579
Joined: Wed Oct 19, 2016 15:18
GitHub: Andrey2470T
In-game: Andrey01
Location: Russia, Moscow

Re: Need a vehicle movement expert!

by Andrey01 » Post

Still a question: is my algorithm true? If no, does anybody know how it should be written correctly? I am pretty sure there are few people that have skills at the creating physics of vehicles as they already made the similar mods.

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests