xtreampb Posted November 5, 2013 Share Posted November 5, 2013 Other than me doing constant gravity tests in my code, is there a way to set 2 objects to have a gravitational pull and which ever object i'm closer to, i will begin to 'fall' towards? Quote bool Life() { while(death=false) { if(death==true) return death; } } I have found the secret to infinite life Did I help you out? Like my post! Link to comment Share on other sites More sharing options...
Josh Posted November 5, 2013 Share Posted November 5, 2013 Internally, the gravity value is just a force added to each active body. So if you have more complex logic like your describe, adding the force you want would be the only way. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
xtreampb Posted November 5, 2013 Author Share Posted November 5, 2013 just so that i know how it is done calculated. I'm assuming that you are using the setforce function and applying it to the negative y axis. Is that value being increased every second? what is the equation you are using if you don't mind me asking? Quote bool Life() { while(death=false) { if(death==true) return death; } } I have found the secret to infinite life Did I help you out? Like my post! Link to comment Share on other sites More sharing options...
Josh Posted November 5, 2013 Share Posted November 5, 2013 It just calls AddForce(gravity) where gravity by default is 0,-9.8,0 times mass: Vec3 force = (spaceship->GetPosition(true) - planet->GetPosition(true)) * spaceship->GetMass(); spaceship->AddForce(force); Technically, gravity increases as you get closer to an object though, so it should really be something like this: Vec3 force = (spaceship->GetPosition(true) - planet->GetPosition(true)) * spaceship->GetMass(); const float gravityrange = 100; force *= 1.0 - min(force.Length() / gravityrange,1.0); spaceship->AddForce(force); If you do this in the UpdatePhysics callback or script function, it will only get called for active bodies, and it will be called once per physics update. Fun physics fact: See how I multiplied the force by the object's mass? That's the reason a piano and a walnut will fall at the same speed (not counting wind resistance). 2 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
xtreampb Posted November 6, 2013 Author Share Posted November 6, 2013 I could be loosing my mind but was is the min function that you call, and what is 'the magnitude' of a vector. Quote bool Life() { while(death=false) { if(death==true) return death; } } I have found the secret to infinite life Did I help you out? Like my post! Link to comment Share on other sites More sharing options...
Josh Posted November 6, 2013 Share Posted November 6, 2013 Magnitude = length. The min function is a C++ built-in thing. I think in Lua there is math.min or you can just call the Leadwerks command Math::Min(). Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.