## Gradual Acceleration and Deacceleration

Discuss new features and future development.

### Gradual Acceleration and Deacceleration

hello

i just wanted to know as to what factors of body and shape should i work on to get a gradual acceleration and deacceleration of a car shape object.
anupgupta

Posts: 13
Joined: Sun Sep 19, 2010 5:04 am

### Re: Gradual Acceleration and Deacceleration

When you say car shape, I assume that you mean a chassis with wheels jointed to it.

The best way I've found to control a car's motion is to attach a simple motor joint between one or both of the wheels and the chassis. By setting the motor's rate and maximum force, you can give it a nice smooth acceleration.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/

slembcke

Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

### Gradual Acceleration and Deacceleration

well currently the situation is like
1. it is a top view of a car. so i have taken the car to be (as a box shape. no chassis or wheels attached)

vehicle->vehicleBody = cpSpaceAddBody(commonDataRef->chipSpace, cpBodyNew(vehicle->mass, cpMomentForBox(vehicle->mass, 18.0f, 32.0f)));
vehicle->vehicleBody->p = vehicle->position;
vehicle->vehicleBody->v = vehicle->velocity;

vehicle->vehicleShape = cpSpaceAddShape(commonDataRef->chipSpace, cpBoxShapeNew(vehicle->vehicleBody, 18.0f, 32.0f));
vehicle->vehicleShape->e = 0.0f;
vehicle->vehicleShape->u = 0.8f;

whenever the objects come near they slow down(deaccelerate and stop). and when they move they gradually accelerate(in iphone when i touch that car and swipe it).
i was just looking for, as to what factors of shape or body do i have to work on to achieve this.
anupgupta

Posts: 13
Joined: Sun Sep 19, 2010 5:04 am

### Re: Gradual Acceleration and Deacceleration

Are you just controlling the velocity of the cars directly? In that case just add or subtract a certain length from the velocity each frame.

For a top down game, you might also want to look into how the tank demo works: http://code.google.com/p/chipmunk-physi ... emo/Tank.c (also included with the library distribution)
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/

slembcke

Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

### Re: Gradual Acceleration and Deacceleration

currently yes i am controlling the velocity of the cars directly.
but may be i was thinking if there could be a better way of slowing them down or accelerating them and not manually tamper the velocity.
basically the velocity of every car is different.
anupgupta

Posts: 13
Joined: Sun Sep 19, 2010 5:04 am

### Re: Gradual Acceleration and Deacceleration

You could play with force too, since that is basically acceleration. I'm not sure about top down games but i don't know of a way to get stuff moving manually without some sort of tampering. Though force might give you better results. Then you can set a velocity limit for max speed.

pat

Posts: 53
Joined: Tue Jul 20, 2010 7:55 pm