Page 1 of 1

Object Gravity Relative to Normal

Posted: Thu Feb 09, 2017 5:50 pm
by miravista
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

Re: Object Gravity Relative to Normal

Posted: Tue Feb 14, 2017 10:48 pm
by Cry-Flare
Unfortunately I cannot help but seems you got some info from the AnswersHub, I am interested to see your results if you get this working, Good luck :).

Re: Object Gravity Relative to Normal

Posted: Sun Mar 19, 2017 1:49 am
by fightergx
a new prey?

;)

:D

Re: Object Gravity Relative to Normal

Posted: Sun Mar 19, 2017 5:46 am
by gshot
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: