Hi,
I'm experimenting with gravity, where instead of a direction, objects fall to a point, which lies in the middle of a static circle.
In practice, it is like a planet.
However, I'm having a little trouble moving a character around. In order to move, I force the character (a circle) in a direction perpendicular to the angle towards the planet.
The problem arises when the character floats off the planet. I assume it is because it still has the velocity of the last few seconds, when the angle toward the planet was different.
Its kinda hard to explain, so here is a video.
Any solutions? How could 'translate' the velocity to the new perspective?
Lucas
Gravity Troubles
-
- Posts: 54
- Joined: Wed Sep 26, 2007 2:34 am
- Contact:
Gravity Troubles
Tangame - a tangram puzzle game with physics.
http://code.google.com/p/tangame/
http://code.google.com/p/tangame/
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Gravity Troubles
To get a correct clockwise/counterclockwis vector, normalize then get the perpendicular vector of the delta from the position of the object to the gravity point.
Something like this:
Then you can multiply this against your forces:
Something like this:
Code: Select all
cpVect direction = cpvperp(cpvnormalize(cpvsub(body.p, gravity_point)));
Code: Select all
body.f = cpvadd(body.f, cpvmult(direction, force));
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 54
- Joined: Wed Sep 26, 2007 2:34 am
- Contact:
Re: Gravity Troubles
That's what I'm doing, and it would work fine if the direction to the gravity point never changes. It does, however, and velocity from previous forces are pointing in the wrong direction. What I'm asking is how I can make the velocity point in the new direction. Maye cpvrotate (except I have no idea how complex rotation works)?
Watch the video to help explain.
Watch the video to help explain.
Tangame - a tangram puzzle game with physics.
http://code.google.com/p/tangame/
http://code.google.com/p/tangame/
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Gravity Troubles
Increase gravity and/or drag? I don't know if you want to fudge the velocity numbers. That seems like an odd thing to do to me.
If you wanted to try the rotation idea, cpvrotate() the velocity by the normalized delta, then cpvunrotate() by the previous normalized delta. That's the best thing that I canthink of.
If you wanted to try the rotation idea, cpvrotate() the velocity by the normalized delta, then cpvunrotate() by the previous normalized delta. That's the best thing that I canthink of.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Who is online
Users browsing this forum: No registered users and 6 guests