Object Gravity Relative to Normal

#1
Hello!
Is it possible to set an objects gravity local to another objects normal? A friend showed me the concept in Unity, but I'm unsure of what I would need to do it in Cryengine

Image

I don't necessarily need it for an animation driven character, but for any rigidbody entity.
As always, thanks for any answers or information that will get me started in the right direction!
-Moose
Edit: I am told that most of it was spline controlled

Answers
Last edited by miravista on Tue Feb 21, 2017 6:35 pm, edited 1 time in total.

Re: Object Gravity Relative to Normal

#4
You can easily achieve this in C++. Simply set the gravity of an entity to the surface normal of an object. I did this for the FPS and TPS template character to walk on any surface which also required setting the up direction of the character to the surface normal direction to get the correct orientation. I'll post some code when I get home tonight.

Edit:

It's as simple as this for the FPS and TPS templates player character, I wrote this code somewhere in PlayerAnimations.cpp:

Code: Select all

Vec3 n = m_pPlayer->GetMovement()->GetGroundNormal(); //ground normal is not just the terrain normal it can be any object's normal
Quat normalRotation = Quat::CreateRotationV0V1(Vec3Constants<float>::fVec3_OneZ, n.GetNormalized());
correctedOrientation = normalRotation * correctedOrientation;
correctedOrientation = Quat::CreateSlerp(GetEntity()->GetWorldRotation(), correctedOrientation, 0.06f); //smooth rotation change when transitioning between faces

pe_player_dynamics pd;
pd.gravity = -n.GetNormalized() * 10;
GetEntity()->GetPhysicalEntity()->SetParams(&pd);

GetEntity()->SetPosRotScale(GetEntity()->GetWorldPos(), correctedOrientation, Vec3(1, 1, 1));


If you need it for some physical entity:

Code: Select all

//Do raycast with RayWorldIntersection to get the hit normal and then simply do this:

pe_params_flags fp;
fp.flagsOR = pef_ignore_areas;
GetEntity()->GetPhysicalEntity()->SetParams(&fp);

pe_simulation_params sp;
sp.gravity = -n.GetNormalized() * 10;
sp.gravityFreefall = -n.GetNormalized() * 10;
GetEntity()->GetPhysicalEntity()->SetParams(&sp);


You need to remember that you need a starting gravity with which you drop onto a surface and from there you can update the gravity of your physical entity to the surface normal as you move around on the surface. Also you might need to update the direction of the raycast according to your physical entity's orientation. You could even use custom area shapes created in the editor and define areas where gravity changes.

All depends on what kind of object you will be using and what exactly you will be doing though. These are just some examples I've given. Just wanted to show setting a local gravity for an entity is as simple as setting some physical entity params in code. Gets a little more complicated if you have to have the correct rotation for your entity but I've also included an example of that.

Here is a video to show it works:
My Youtube Channel

Who is online

Users browsing this forum: No registered users and 1 guest