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 Professional Discussion / acceleration of object

Author
Message
Stormbringer
22
Years of Service
User Offline
Joined: 1st Oct 2003
Location:
Posted: 19th Nov 2003 02:52
i've got controls for a vehicle that so far function just fine with forward and reverse with turning in both directions ;back and forth.
problem i've been having is that i want acceleration in both directions. This is not a racing game but a vehcle combat game upkey the vehicle moves forward , downkey it moves in reverse. What im tring to do is get the cars to move accelerate to speed ;instead of flying into it immediatly; then slowdown if key is released. plus get the car to slowdown and stop then go into reverse if down key is pressed and viceversa. im sure its got to be easy without complicated math theories. i hope.

any help would be appreciated thanx
MikeS
Retired Moderator
23
Years of Service
User Offline
Joined: 2nd Dec 2002
Location: United States
Posted: 19th Nov 2003 02:58
You could do something like



Alright, don't take my code for correct syntax, but something along the lines of a simple step command may work. Just play around with the numbers a little.(1-100 might not be a good enough range for acceleration, or you may want to decrease the pace the number steps.(0.01)

Well, hope this at least gets you started thinking.



A book? I hate book. Book is stupid.
las6
23
Years of Service
User Offline
Joined: 2nd Sep 2002
Location: Finland
Posted: 19th Nov 2003 12:04
well, as long as you keep in mind that the following math works for all cases, it should be simple enough:

Speed = Speed + Acceleration
Speed is "0" because we are not moving yet. Acceleration = "0" because no key is being pressed. That results in 0.
Now if we press upkey, the Acceleration will be changed to "1". This causes the speed to rise, as long as you hold the key down. If you press downkey, the acceleration is "-1". Now if we have speed of "2" the math would be like this:
Speed = 2 + -1
that would result in 1.

So it's really that simple.
You can always cap the speed at whatever you want.

Keyboard not detected. Press F1 to continue.
Stormbringer
22
Years of Service
User Offline
Joined: 1st Oct 2003
Location:
Posted: 20th Nov 2003 01:51
i,ve tried ad you had both suggested first nothing happened then i had a thought because of the size of my arena i had to use numbers less than 0 for all of my movements in decimals basicaly 0.4 or -0.4 depending on my direction
when i put
speed=1
move objnum.,speed
the vehicle the car flew across the screen at a high speed
so new question, do i have to use whole numbers only when i set up acceleration and braking?
if not than please explain more i really don't look forward to having to have to redesign my level.
also, if it is to small(currently 125,125,10,10) what would be a decent size ? As a test i quickly multiplyied the matix only by 10 and my frame rate droped from 130 to 56 leaving every thing else as it was.
Could the size of things also be part of the problem i,ve been having with leaks in my collisions -car hits a box multiple times then eventually will decide to pass through it ???

I figure the framerate had to drop so much due to when i inreased the matrix because i'm useing an Anthlon xp 2600 with a Geforce 4 mmx

anyways back on the subject do i have to use whole numbers only or can they broken into decimal form?
BillR
23
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 20th Nov 2003 07:05
Sure you can use floating point ex.(.01) numbers for your acceleration and braking.

Search the forum for either acceleration or gravity(which is also an acceleration) posts, and read through the different kinds of code used. Some of them are easier to understand then others.

Or just try fractional numbers on your own, they will do the trick.
Beta 1
22
Years of Service
User Offline
Joined: 27th Aug 2003
Location:
Posted: 20th Nov 2003 14:01 Edited at: 20th Nov 2003 14:02
yeah I had problems with this until I realised one of my vectors was an integer instead of a float (DOH!)

To get the slowing down when the key is released you need to use a drag force of some kind.

One way to do it is to add speed=speed*0.99 each turn. This causes the speed to return to 0 if there is no accleration

The other is to use a proper drag force which is either F*speed (where C is the drag constant) for rolling resistance (friction) or C*Speed*speed for aerodynamic drag.

So Speed=Speed+accleration+friction+drag

OR V1=Vo+A+(F*Vo)+(C*Vo*Vo)

You will need to play around with the drag constants to get it to work well.

If you use either system you probably wont need to set a top speed as the drag will limit it.

(nb if your acceleration is to low it wont over come the drag in either case and the car wont move)

I would really reccomend this web site as it explains it better than me and has some example values to put into the formula

http://home.planet.nl/~monstrous/tutcar.html
deX
22
Years of Service
User Offline
Joined: 12th Nov 2003
Location:
Posted: 20th Nov 2003 15:20
its probably a good idea to add a line to that, like:

if speed<0.01 then speed=0

so your car will actually stop, instead of just getting slower and slower.


-deX
Beta 1
22
Years of Service
User Offline
Joined: 27th Aug 2003
Location:
Posted: 21st Nov 2003 12:53
I never realyl bothered - once the speed is that slow its not going to make much difference!

Login to post a reply

Server time is: 2026-07-26 19:46:53
Your offset time is: 2026-07-26 19:46:53