PDA

View Full Version : Car drifting


wild8900
09-23-2006, 07:59 AM
How does the drifting for the cars on UN work? In other words, how would I make drifting for a car script that I have. It moves in the 360 degree direction that changes to the arrow key direction. How does drifting work in general?

EDIT: btw, I am willing to post parts of my script if it helps...

Twinny
09-23-2006, 03:38 PM
Would be much the same as an ice skating rink script. I can provide a GS1 example though I'm not sure how useful that would be. PM me if you would like it.

wild8900
09-23-2006, 06:24 PM
Thanks, im better with gs1

Crono
09-23-2006, 07:01 PM
they got drifting on un? if so i should play there all day :P

zim5354
09-23-2006, 07:50 PM
they got drifting on un? if so i should play there all day :P

UN cars suck. :(

Yen
09-23-2006, 08:03 PM
What do you mean by drifting?

k0rupt_ed
09-23-2006, 08:20 PM
they have drifting? wtf?

wild8900
09-23-2006, 09:24 PM
not really drifting but what I mean is, when you are giong in one direction but turn to A different one really quick, you still move in the other direction a little bit with inertia.

zim5354
09-23-2006, 09:33 PM
not really drifting but what I mean is, when you are giong in one direction but turn to A different one really quick, you still move in the other direction a little bit with inertia.
There scripting is just bad im pretty sure that wasnt intended lol.

Chompy
09-23-2006, 10:18 PM
360 degree

For that, cos and sin would be good

wild8900
09-23-2006, 10:22 PM
right, I already know that, my car script can move in 360 degrees with some pretty good collision detection. I just chose to limit it to 8 or 4 directions like UN.

Chompy
09-23-2006, 10:25 PM
you made it like, when pressing left or right, angle++/-- and then up is acceleration and down is brake?

Yen
09-24-2006, 12:40 AM
Well, you'll want to have two variables: xvelocity and yvelocity

While the car is moving, you'll increase the x/y by xvelocity and yvelocity.
When you press the up key, you'll decrease y velocity by the acceleration until it reaches the speed limit. When it reaches the speed limit, it stops increasing the velocity.
Do the same for the other keys.


function onCreated() {
this.xvelocity = this.yvelocity = 0;
this.acceleration = .1;
this.speedlimit = 1;
}

function onTimeout() {
for (k = 0; k < 4; k++) {
if (keydown(k)) {
this.xvelocity = limit(this.xvelocity + vecx(k) * this.acceleration,-this.speedlimit,this.speedlimit);
this.yvelocity = limit(this.yvelocity + vecy(k) * this.acceleration,-this.speedlimit,this.speedlimit);
}
}
}

function limit(val,min,max) {
if (val < min) val = min;
if (val > max) val = max;
return val;
}

Chompy
09-24-2006, 01:17 AM
that Script looks good :) well you only miss one thing :O

setTimer(0.05); in timeout and/or in onCreated()?

or not needed? :confused:

Yen
09-24-2006, 06:19 PM
I didn't give the full script, I just gave a general idea of how to do it.

Chompy
09-24-2006, 09:44 PM
ah, I was wondreing, because I know you can script :P

^^

ApothiX
09-25-2006, 04:06 PM
UN cars suck. :(
**** >:[

There scripting is just bad im pretty sure that wasnt intended lol.
Actually, it was. Incase you haven't noticed, if you make a sharp turn with a car in real life, the momentum from the original direction you were travelling doesn't just magically dissapear.

Twinny
09-25-2006, 04:12 PM
It wouldn't surprise me if the "drift" was caused by bad scripting =p

ApothiX
09-25-2006, 05:47 PM
It wouldn't surprise me if the "drift" was caused by bad scripting =p
Reed b4 u post plx.