Gravity Wells and Black Holes
by Russell Tracey · in Torque Game Builder · 03/31/2005 (4:52 pm) · 44 replies
I'm attempting to produce a gravity well type effect which sucks objects towards it in a black hole like way. I've tried a mounting an object to the centre of the black hole and setting it to chase the mount point but this doesn't seem to work. I have tried several different force values but they are either too weak or too strong. If its too much then the objects go straight to the centre, if its not enough they fly right past but gradually slow until they are stop half way off the screen.
What I am trying to achieve is a black hole that will start to drag a ship into it if the ship gets too close, if the ship however has enough force it can escape the black hole but its direction will be altered slightly due to the effects of the black hole.
Has anyone got something like this working?
What I am trying to achieve is a black hole that will start to drag a ship into it if the ship gets too close, if the ship however has enough force it can escape the black hole but its direction will be altered slightly due to the effects of the black hole.
Has anyone got something like this working?
About the author
#42
07/10/2006 (10:49 am)
Rather than just email out a bunch of copies - wouldn't this be a great addition to the TDN?
#43
I find this gives a better feel for gravity. I added the m_forceMgr class which basically is an array of forces affecting an object so that you can have multiple sources of gravity, and thrusters, and whatever else you want all affecting an object at the same time.
The problem I'm running into now is that it seems OnStay only affects the object nearest the center of the trigger. If I have two or more objects in the same gravity well then only one gets the gravity applied.
The only solution I can think of is to keep track of all the objects that enter a trigger at OnEnter time and remove them at OnLeave time. Then when I get to OnStay I would cycle through my array of objects. This would work better, but I suspect if two objects enter the trigger at exact same time I would have the same problem of only one object actually triggering the OnEnter callback. Is there a better way to handle this?
I do have the pro license, but I've been trying to avoid getting into modifying the engine source for this first project.
12/24/2006 (9:24 am)
I've been playing around with gravity and have a fairly modified version of this. My gravity equation looks like this:function GravityWell::OnStay( %this, %obj )
{
%vecBetweenBodies = t2dVectorSub( %this.getPosition(), %obj.getPosition() );
%distBetweenBodies = t2dVectorLength( %vecBetweenBodies );
%gravityFactor = mClamp((%this.m_radius-%distBetweenBodies), 0, %this.m_radius)/%this.m_radius;
// Might want to try gravityFactor^2
%forceStr = %this.m_strength * %gravityFactor;
%impulseForce = t2dVectorScale( t2dVectorNormalise(%vecBetweenBodies), %forceStr );
%obj.m_forceMgr.AddForce( GetWord(%impulseForce, 0), GetWord(%impulseForce, 1) );
}I find this gives a better feel for gravity. I added the m_forceMgr class which basically is an array of forces affecting an object so that you can have multiple sources of gravity, and thrusters, and whatever else you want all affecting an object at the same time.
The problem I'm running into now is that it seems OnStay only affects the object nearest the center of the trigger. If I have two or more objects in the same gravity well then only one gets the gravity applied.
The only solution I can think of is to keep track of all the objects that enter a trigger at OnEnter time and remove them at OnLeave time. Then when I get to OnStay I would cycle through my array of objects. This would work better, but I suspect if two objects enter the trigger at exact same time I would have the same problem of only one object actually triggering the OnEnter callback. Is there a better way to handle this?
I do have the pro license, but I've been trying to avoid getting into modifying the engine source for this first project.
#44
I'm trying to compile your c++ code for TGB 1.60. I changed the fx names to the new correct t2d ones and compiled, with no errors. I added the script you wrote in the Readme.txt and ran it.. once again no errors, but it seems like the code isnt even running. Any ideas??
Thanks!!!
12/16/2007 (12:35 am)
Melv,I'm trying to compile your c++ code for TGB 1.60. I changed the fx names to the new correct t2d ones and compiled, with no errors. I added the script you wrote in the Readme.txt and ran it.. once again no errors, but it seems like the code isnt even running. Any ideas??
Thanks!!!
Torque Owner Thomas Buscaglia