Accelaration and deccelaration

Started by Cpt Ezz, Mon 15/06/2009 07:38:30

Previous topic - Next topic

Cpt Ezz

i have my ideas how to do it, and i'm working on it now
but if any one knows for serten who to make a character (car) slow down and speed up it would be a great help

Akatosh

One way would be to manipulate its WalkSpeed property.

Or you could bypass the normal movement system and build something from scratch, involving a float variable or two, the repeatedly_execute part of the global script, a timer and the cCar.X and cCar.Y properties. You make the call.  :=

GuyAwesome

#2
But the walk speed can't be changed while a character is moving, can it? So it might be difficult to get smooth movement if you go that route.

Edmundito's Tween Module might be of use here:
Quote
For example, if I'm moving a car from point a to b, I want it to look like it's decelerating when as of to simulate breaking, so I can do that.
And there are AGS driving games (e.g. zabnat's Taxi demo) that prove it can be done. zabnat's demo thread also features the source code, for anyone to use or learn from. (I think it uses the 'bypass normal movement' method.) I'm fairly certain there's other examples out there, too.

EDIT:
Ah, nevermind - I see you're familiar with some AGS driving games. Yes, contacting the authors is probably a good idea.

Cpt Ezz

i know completely off topic but how do i install the tweens module?

Khris

Right-click the Scripts node in the project tree.

Cpt Ezz

#5
i know that much
and you open the global script.asc
but how do import the scripts into the game
do i have to type it all out or what?

Edit: Thanks for advice about making my own akatosh i was thinking about that

GuyAwesome

Quote
i know that much
and you open the global script.asc
No, you select 'Import script...' then you navigate to wherever you saved the module and, well, import it. Left-clicking will expand out the node, giving you the option to open the global script. Right-clicking gives the option to import a module or create your own.

Trent R

Then read the instructions of use in the module's manual (usual contained in the module's script header, so that you can read it in AGS)

~Trent
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

zabnat

First of all, what ever it is you will be manipulating its x and y coordinates directly.

Here's a snippet that involves straight line physics in Taxi source (with added comments) (most of the variables are structs, so that's why they have .x):
Code: ags

Fdrag.x = -Cdrag * velocity.x * velocity.x * velocity.x; 	// Cdrag = 0.1 - real formula is -Cdrag * velocity.x * abs(velocity.x)
Frr.x = -Crr * velocity.x; 					// Crr = 20.0
F.x = Ftraction + Fdrag.x + Frr.x; 				// Ftraction = 8000.0
acceleration.x = F.x / mass; 					// F = ma, second law of motion
velocity.x += acceleration.x * delta_time; 			// delta_time is time the frame takes so in 40fps it would be 1/40

And now that you have velocity, you can move the car sprite like:
Code: ags
player.x += velocity.x * delta_time

You multiply with delta time to get the units right. Acceleration is m/s2 and velocity is m/s and the distance to move the player is m.

The values are tweaked to get a toy car like acceleration and top speed. That's why drag formula is tweaked to make it grow faster with velocity. And ofcourse for braking (decceleration) you just flip the sign of Ftraction and the velocity will come down. When at full stop and you "brake" this way the car will go on reverse.

Hope this helps.

Cpt Ezz

WOW thats a load full :o :o
i don't really know if it will help but i'm really thankfull of the script
i will try to use it if i can
so thanks a lot

Cpt Ezz

Thanks again
I have just started looking at my game again and i just want to clear up some things with the script....
First where is the characters name in all this?
Which ones are bools and variables and all that(so i can add them at the top)?
So is that all that i need nothing more?
Sorry for all the questions but i don't what my computer to explode when i put the script in(i have a feeling it will do that)

zabnat

About the code above:
There are no characters or objects involved in that code, the code is actually not AGS-specific. All the things in the code are float variables (well Cdrag and Crr can be constants) and even the result (player.x) is a float. After this physics calculation you need to draw the stuff on the screen. So you set the coordinates of the character or object (whatever it is you are using for your car) and draw them (first you convert coordinates from float to int). This should be all that you need on the physics department for straight driving car. In addition you'll need to assign coordinates to the car object (as I said above) and maybe assign a button or buttons to control acceleration decceleration (controlling the value of Ftraction).

tzachs

You can do this easily with the Tween module like this:

Code: ags

int toX = 50; //Your x here
int toY = 50; //Your y here
float timeInSeconds = 4.5; //Your time here
cCar.TweenPosition(timeInSeconds, toX, toY, eEaseInTween); 


This will accelerate your car's position from it's current position to 50,50 in 4.5 seconds.
In order to decelerate just replace 'eEaseInTween' with 'eEaseOutTween'.

Also, if you have a driving animation to your car, you can decrease and increase your animation speed together with the position to get a better effect, with this code:
Code: ags

int toX = 50; //Your x here
int toY = 50; //Your y here
float timeInSeconds = 4.5; //Your time here
cCar.TweenPosition(timeInSeconds, toX, toY, eEaseInTween, eNoBlockTween);
cCar.TweenAnimationSpeed(timeInSeconds,  cCar.AnimationSpeed -20);


This will speed up the driving animation for the car to be 20 less than the current animation speed which will give an effect of acceleration (you will probably need to play with the numbers a bit though). Use +20 for deceleration effect.

SMF spam blocked by CleanTalk