Jump to content

Entity::GetForce()


Recommended Posts

Similar to the newton function here I'd like to be able to get the amount of force applied to an entity in the last physics update.

Entity::GetForce() or maybe Entity::GetAppliedForce()?

I want to know what direction an object is being pulled - this is not always going to be the velocity.  An object can be stationary yet still have a large force acting on it.

  • Upvote 1
Link to comment
Share on other sites

Quote

This function is only effective when called from NewtonApplyForceAndTorque callback.

I think this is for processing forces right before they are applied.

Forces can be applied two ways:

  • Collision
  • Programmatic

In both cases, you have control over or access to the time that force is applied.

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

Why would you need that, if you already have access to that information when it happens?

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

 AddForce() could be called anywhere within the program, and how would I get the force applied by collision?  The Collide function in the components only has speed.

I need it for finding out the direction the object is being pulled in so I can align my player controller to gravity as it falls.

Link to comment
Share on other sites

The collision includes the normal, which gives you the direction. I don't know how to get the "force" of a collision. This function does not:
https://github.com/mmozeiko/Squares3D-Android/blob/dc7002d3e638a9ed0ffd090dc52168029321cec7/jni/newton/coreLibrary_200/source/newton/Newton.cpp#L2095

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

Perhaps something like this for tracking Entity::AddForce at least?  The total force (including collision force) can only be retrieved from with the callback like you said.  I more interested in knowing what the force is that is about to be applied to the physics object by code.

MyComponent {

virtual void PhysicsUpdateStart(float& applied_force_this_loop){
	applied_force_this_loop = 0.0f;  //Do what ever you want with the force that is about to be applied.
}
}


//Maybe it could track what is being added?
Entity::AddForce(Vec3 new_force){
	applied_force_this_loop += new_force
}

//Once the physics update has completed
End_PhysicsUpdate(){
	//All entiites force can be reset to zero
	applied_force_this_loop = 0;
}

PhysicsUpdateStart could even be called from the torqueandforce callback - if it's thread safe...

void callbackForceAndTorque(const NewtonBody* body)
{
	auto total_force_ready_to_apply = 0;
	NewtonBodyGetForce(body, total_force_ready_to_apply);

	auto componet = body->GetUserData();
	componet->PhysicsUpdateStart(total_force_ready_to_apply);
	NewtonBodyAddForce(body, total_force_ready_to_apply);
}

 

Link to comment
Share on other sites

The documentation above says that the function will return zero if the two bodies are in motion, because the contact is not a force but an impulse. This is getting beyond my knowledge of physics. The best approximation I can think of is to take the normal and speed * speed of the collision times the other body's mass, and that's your kinetic energy, or "force".

  • Thanks 1

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

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