# Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

### DarkBASIC Discussion / car stearing controll

Message
Posted: 21st Dec 2013 23:26
Hi all,

I am trying to make a simple car move arround the flat matrix.

It doesn't have to be gta like, but i managed the acelerate and the breaks.

How can i stear when the gasspaddle (upkey) is slightly pressed?
the car turns around its own axis. It looks not real. When at greater speed, the turn is oke.

I Tryed with only the left stearing, but it still doens't look nice.
Anyone any idee?

here is my code.

Greetings.

Toedeledoki
Posted: 24th Dec 2013 22:29
Maybe you should try to use arithmetic functions to determine the new position of the car and the to move it there.

ere is a very simple move-around-program to control our car:

I'll attach the program, the 'media' and an executable version in a rar-file, though you can try it out

merry xmas

#### Attachments

Posted: 29th Dec 2013 14:26
It looks unnatural because the centre of the car body shouldn't be the centre of rotation. I haven't worked with 3D for a while but I think there is a way to offset the object (limb 0?) so that it will rotate at a realistic centre of rotation (towards the rear of the car).

Formerly OBese87.
Posted: 29th Dec 2013 19:04 Edited at: 29th Dec 2013 20:05
For steering a car, the effect of steering is only experienced as a function of change in position. So when the car moves forward, try altering the direction of travel by a delta multiplied by speed, each frame. If the steering wheel is straight, the delta is 0. If it is left, it is negative, right is positive. This way rotation is dependent on motion. Each frame, rotate the car by delta*speed, then move forward in that new direction.

If you are using just keys for steering, and not the mouse, you can smooth the steering wheel with this:

...where delta0 is the result of your key presses (-30, 0, +30 for example). The closer to 1 decayFactor is, the slower the wheel will respond. You could apply an identical filter to the speed to give the car some inertia. When you press the up key, it will accelerate forward. When you let it go, it will coast to a stop. In addition, if you wish it to start and stop more accurately with both kinetic and static coefficients of friction, you can switch between two different decayFactors for the speed, depending on the current speed. Your main decayFactor for speed would be close to 1. But any time your speed is below a threshold (near 0), use a lower decayFactor instead that is not close to 1. This would be more for slowing down and then stopping than for accelerating. You could use it just for stopping if you wanted.

Not sure if the BASIC syntax is accurate, but here is the psuedo-code at least.

Or in place of moveforward psuedo-code, you could use Attila's sin and cos as mentioned above to calculate the new positions.

P.S. Your decayFactors should be based on your framerate, since each it's repeated per frame. To convert from it in seconds to what it would be per frame, it's the decayFactorSeconds raised to the power of (1 / FPS):

An example of decayFactorSeconds would be that if you set that to 0.2, then at the end of 1 second, your speed would be 0.2 what it was.

Q: ...you mean computer imagery was still based on the paradigm that the world was flat? Even into the 21st century??? Talk about doing something the hard way!

A: Yep! Back then people would render simple shapes with complex meshes of thousands of flat little triangles. Next to the bottleneck processors they used, it's the main reason why their computers were so slow. In the last days of the religious atmosphere of centralization and trade, corporate dogmas had people believing that flat was faster.
Posted: 30th Dec 2013 19:05
Great post, The Tall Man!

Homer, you must look up the difference between velocity and speed. Speed is a scalar quantity, it has no direction and therefore cannot be negative. I would recommend learning the maths behind what Tall Man is saying, it isn't too hard to do and will give you great results. There are some built-in commands that could help though, such as CURVEVALUE, NEWXVALUE, NEWYVALUE and NEWZVALUE, but you need to know the maths to know what to do with them anyway.

Formerly OBese87.
Posted: 30th Dec 2013 21:50
Thanks for the information all.

I read in the help function about the car acceleration with curvevalue. Shall try that.

I don't like the move object, rather use positionl object.

before this question I found some info about car math in games. I try to keep it simple with the acceleration. But stearing looked not good.

I shall experiment with all your commands. Thanks again.

Greetings Jeroen

Toedeledoki
Posted: 3rd Jan 2014 21:52
Check out waffles car racing tutorial if you have the time. Has a lot of information for DBC:

http://forum.thegamecreators.com/?m=forum_view&t=137817&b=10

Posted: 4th Jan 2014 00:26
tnx,

the hollidays are just over, so i have to find some extra time to read, lol.