SpiderPig Posted September 11, 2018 Share Posted September 11, 2018 For gravity I was using this code; float _force = -9.8f * entity->GetMass(); entity->AddForce(0.0f, _force, 0,0f); But I have to increase the mass to big numbers in order to achieve realism and the formula is wrong anyway. Every second, the object should be going 9.8ms faster than before (ignoring friction) and the acceleration should be regardless of weight. The force on the earths surface is mass x acceleration, however acceleration in free fall is the same for each object. float _force = -9.8f; Vec3 _entityVelocity = entity->GetVelocity(true); entity->SetVelocity(_entityVelocity.x, _entityVelocity.y + (_force), _entityVelocity.z, true); This code is better but maybe a little too fast, it's hard to tell. I'm calling it in the objects Actor in the update-physics loop, as far as I'm aware this runs at 60FPS regardless of frame rate. So that means that _force should be equal to "9.8 / 60" but that's too slow... I'd like to use AddForce() but the numbers don't seem right. Any physics gurus here that might know why AddForce() doesn't do the job? And why 9.8 / 60 is too slow? Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted September 11, 2018 Author Share Posted September 11, 2018 From what I can tell, the acceleration starts off fast, then the faster the object gets the slower it accelerates... EDIT : SetDamping(0, 0); fixed that Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted September 11, 2018 Author Share Posted September 11, 2018 if (Time::Millisecs() > lastTime + 1000L) { velChange = entity->GetVelocity(true) - lastVelocity; lastVelocity = entity->GetVelocity(true); lastTime = Time::Millisecs(); } I used this code to verify how fast it was accelerating per second, after setting Damping to 0 the change in velocity was a constant 9.8ms per second. So the original code works now. float _force = -9.8f * entity->GetMass(); entity->AddForce(0.0f, _force, 0,0f); Though it still seems too slow. The object just isn't falling fast enough. I could make it higher to it look right but I'd like to know why 9.8ms isn't enough... Quote 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.