pushing an object.

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
JBGame
Posts: 23
Joined: Thu Feb 04, 2010 10:46 am

pushing an object.

Post 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?
Zeus
Posts: 24
Joined: Sun Dec 13, 2009 1:03 pm
Location: Germany :P

Post 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
JBGame
Posts: 23
Joined: Thu Feb 04, 2010 10:46 am

Post 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.
Virion
Competition winner
Posts: 2148
Joined: Mon Dec 18, 2006 5:04 am

Post by Virion »

the easiest way is to use a physics engine (bullet, newton, physx, etc)
JBGame
Posts: 23
Joined: Thu Feb 04, 2010 10:46 am

Post by JBGame »

hi,

i don't want to use a physics engine, i'm trying to build my own simple physics engine :)
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post 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 ^^
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
Anteater
Posts: 266
Joined: Thu Jun 01, 2006 4:02 pm
Location: Earth
Contact:

Post 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.
Zeus
Posts: 24
Joined: Sun Dec 13, 2009 1:03 pm
Location: Germany :P

Post 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 ...
Post Reply