Jump to content

SetVelocity vs Addforce


SpiderPig
 Share

Recommended Posts

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...