Physics: Where to find the required info

#1
Hello!

I've been viewing the samples, along with other docs (where I could find them) but the general details on what can be done/ how it's done are very sparse.

I can , and have, copy the physicalization params from the templates but I don't feel that this is a stable solution. I barely understand why I should be using these settings (or others) with obvious exceptions such as PE_LIVING (one of the few things that are over-documented).

For example, why should I keep the pivot at the players feet?
When should I be using a Capsule?
Why do playerDynamics and playerDimensions have duplicate values? (e.g. mass)
Can I set the rotation of the cylinder as well?
According to some code '// sizeCollider specifies the size of the cylinder (x is radius, z is half - height, y is unused).' Why is Y not used but set anyway?

Is there a way of setting up collision hierarchies, similar to what rendering could do (e.g. devide space into 8 large cubes, each cube into 8 smaller cubes, etc. and check progressively deeper) ?

Can I have several capsules (e.g. similar to CSGO for hit-detection) ? Where can I intercept the 'collisions' as they happen? e.g. getting shot via projectile or having an arm 'hit' another object.

I can create my own system for dynamically changing the cylinder settings/orientation/chain-of-hits etc. provided I know how to access the capsule etc. directly (including angle!) , if having several would be an issue, and if I can even implement several capsules......

There's just so much that I want to do but so little documentation or samples. Basically anything that I find feels sparse and I'm putting this out here before I dig through the GameSDK code for a couple days again >.>

Please , please, leave any info you think might help here. Even if it's a link to some docs, at worst I'd say 'seen it', at best you just solved my problems!

Re: Physics: Where to find the required info

#2
Have you seen this?
  • You don't have to keep the pivot at the player's feet. The "playerDimensions.heightPivot" param is simply used as a vertical offset from the ground contact point of your player which is the pivot of your character model. So it should be 0 unless you want something else.
  • The "playerDimensions.heightCollider" is simply a vertical offset of the collider shape from the pivot (player's feet).
  • If you need higher fidelity collisions for your character, you use a capsule instead of a cylinder.
  • pe_player_dimensions struct doesn't have a "mass" param. The physicalization params struct does and this is used when the entity is first physicalized. If you want to change the mass of the player after that you will need to use the pe_player_dynamics struct.
  • An IEntity will have a single IPhysicalEntity attached and this IPhysicalEntity can contain many parts. In this case the cylinder collider is a part. You can set the rotation of an entity's physical parts by using pe_status_nparts and pe_params_part as follows:

    Code: Select all

    pe_status_nparts snp; pe_params_part pp; int nParts = GetEntity()->GetPhysicalEntity()->GetStatus(&snp); for (pp.ipart = 0; pp.ipart < nParts; ++pp.ipart) { pp.q = Quat::CreateRotationV0V1(Vec3(0, 0, 1), Vec3(0, 1, 0)); GetEntity()->GetPhysicalEntity()->SetParams(&pp); /////Bonus code from here on for example purposes////// //Get params after setting new rotation GetEntity()->GetPhysicalEntity()->GetParams(&pp); //pp.pos is in local space so transform it to entity's world space Vec3 worldPos = GetEntity()->GetWorldTM().TransformPoint(pp.pos); //Because we rotated the cylinder from Vec3(0,0,1) to Vec3(0,1,0) //using the CreateRotationV0V1, we essentially do the same here by multiplying the quaternion with the Vec3(0,0,1) //which rotates the vector in the same way to get the forward direction vector Vec3 localForwardDir = pp.q * Vec3(0, 0, 1); Vec3 worldForwardDir = GetEntity()->GetWorldTM().TransformVector(localForwardDir); gEnv->pRenderer->GetIRenderAuxGeom()->DrawCylinder(worldPos, worldForwardDir, 0.05f, 0.5f, ColorB(Col_Red)); }
    That will make the cylinder collider rotate and point in the forward direction of the player. After that it will draw a cylinder at the position of the cylinder collider. I just included this for example purposes and it may be needed by someone at some point. The pp.pos parameter is in local space so you need to transform it into the world space of the player entity.
  • Regarding collision hierarchies, I believe Cryengine already has this in some form but I may be wrong. Why do you need to do this though?
  • You can have several capsules of course. You don't usually create all the colliders in code though. You create them in 3dsmax, Blender or similar. However, you can if you wanted create them all in code and position them at the joints of the character but that will get complicated really quick.

    You can receive collision events through the ProcessEvent function of an entity. Check out HandleEvent function in Bullet.cpp to see how it's done. Same thing can be done for ProcessEvent in Player.cpp, except you check for the ENTITY_EVENT_COLLISION instead of eGFE_OnCollision. Here you can get the collision entities from the EventPhysCollision struct and use my code for getting the parts then check which part of the character (arm, leg, head etc.) triggered the collision event according to their part id:

    Code: Select all

    EventPhysCollision *physCollision = reinterpret_cast<EventPhysCollision *>(event.ptr); IPhysicalEntity* pEnt1 = physCollision->pEntity[0]; IPhysicalEntity* pEnt2 = physCollision->pEntity[1];
Hope that helps :)
My Youtube Channel

Who is online

Users browsing this forum: No registered users and 2 guests