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?
pushing an object.
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
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
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)
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.
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);
}
the easiest way is to use a physics engine (bullet, newton, physx, etc)
My company: http://www.kloena.com
My blog: http://www.zhieng.com
My co-working space: http://www.deskspace.info
My blog: http://www.zhieng.com
My co-working space: http://www.deskspace.info
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 ^^
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 ^^
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
maybe that could help you ...JBGame wrote: i don't want to use a physics engine, i'm trying to build my own simple physics engine
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 ...