Hovering ball Author Message
Mischief0
Member

 Post: #1 Hovering ball Hi there, I'm trying to create a ball, set its initial direction based on the characters head direction, and have it so that it is always hovering off the ground (e.g. if it goes near a hill, it should stay above it). At the moment I've turned the ball actors gravity off, and using either ray / sweep I can add some force beneath it... but it than hovers into space as theres no gravity. If I turn gravity on.. well if the ball goes down a hill its rockets off and I'd like to keep it at a set speed. Pseudo-code creation: actor.pos(thePosition + theDirection * 2); actor.addForce(theDirection * initialForce); update: PhysHit physHit; if(actor.sweep(actor.pos() - Vec(0, 1, 0), &physHit)) { actor.addForce(physHit.dist, Vec(actor.pos().x, physHit.plane.pos.y, actor.pos().z)); }
02-12-2012 09:37 PM
Tottel
Member

 Post: #2 RE: Hovering ball I think you should keep the gravity on, it makes the most sense as well. How about adding a force according to the length of the raycast. The longer the vector, the smaller the force applied to it. I guess that would be a pretty elegant solution, but it would require some tweaking to get it to hover on the good position.
02-12-2012 09:46 PM
Mischief0
Member

 Post: #3 RE: Hovering ball Hmmm that makes sense... example below, seems anything below 9.8 makes and it'll sit on the ground. 9.8 however makes it shoot off... guess its not applying force directly under it. Physics.ray(actor.pos(), actor.pos() - Vec(0, 2,0), &physHit, IndexToFlag(AG_TERRAIN)); actor.addForce(9.8 - physHit.dist, Vec(actor.pos().x, physHit.plane.pos.y, actor.pos().z)); If i set the velocity to a vector, than apply force, doesnt seem to do much either :S
02-12-2012 10:01 PM
 « Next Oldest | Next Newest »