Page 1 of 1

pushing an object.

Posted: Sun Feb 14, 2010 2:49 am
by JBGame
hi,

i need some help pushing an object.
i have 2 spheres, how would move an object depending on which direction i push it from?

Posted: Sun Feb 14, 2010 4:55 am
by Zeus
physiks and programming skills are the answer ;) ...
you can calculate a force that one of the spheres bears to the other(law of action and reaction) and out of the force and the collision point you can get the force and direction of the push ;) ... sorry if there is an easier way already implimented but i don't know of it ... ...

regards zeus

Posted: Sun Feb 14, 2010 8:15 am
by JBGame
i don't have enough math knowledge to do this, i have basic gravity lodged in(don't know if it's correct though, so let me know if it isn't)

Code: Select all

void applyGravity(IMeshSceneNode *node,float mass,float gravity,float friction,float dt)
{
	
		nodeposition = node->getPosition();
		acceleration += mass * gravity;
		acceleration *= friction;
		nodeposition.Y -= acceleration * dt;
		node->setPosition(nodeposition);
}
i have atm is, when sphere1 collides with sphere2, do force = mass * acceleration then set sphere 2 position..what i want is when sphere1 hits sphere2 from the left side, sphere2 will move right, and vice versa.

Posted: Sun Feb 14, 2010 8:16 am
by Virion
the easiest way is to use a physics engine (bullet, newton, physx, etc)

Posted: Sun Feb 14, 2010 9:17 am
by JBGame
hi,

i don't want to use a physics engine, i'm trying to build my own simple physics engine :)

Posted: Sun Feb 14, 2010 10:42 am
by CuteAlien
Collisions are somewhat tricky as they are not really physical. In real-life the physics dosn't have to solve the situation that 2 solid objects which can't overlap are already inside each other. So you don't really find a formula for that (well I guess unless you go down to simulating molecular forces...). Instead you have to find the point of impact and calculate from that one the changes in impulse. I can't do that for you as it's nothing I'm able to solve beside breakfeast.

But an easy trick for a start is - just use some repulsion force. Similar like you calculate your gravity, just instead of gravity you use a repulsion vector which goes for example from the point of collision to the center of each sphere. You keep that vector up as long as they collide (which means objects do collide for a few frames, but you simply don't care). I might actually have been that lazy in some racer I did in the past... results are not perfect, but they'll do if you're short on time or want some quick results ^^

Posted: Sun Feb 14, 2010 1:49 pm
by Anteater
Just cast a ray that starts at object #1's position and ends at the position it was last frame. If object#2 intersects the line, push it away from the line at an equal velocity of object #1. It works.

Posted: Sun Feb 14, 2010 2:01 pm
by Zeus
JBGame wrote: i don't want to use a physics engine, i'm trying to build my own simple physics engine :)
maybe that could help you ...

german:
http://de.wikipedia.org/wiki/Impulserhaltungssatz
english:
http://en.wikipedia.org/wiki/Momentum

your example is a bit more tricky cause your e.g. spheres have a bounding radius and the formulars only work on "mass points" ... so you have to recalculate it ...