C# Movement Help

#1
I am making a first person shooter and have found some difficulty, in unity there are certain statements that can make the player move and I have failed to find them in the Cryengine C# Api Reference.
How can I write these in Cryengine (This is what it should look like in Unity):

Code: Select all

CharacterController.Move = Velocity; //This sets the players velocity to the value assigned but does not ignore collision and can still be stopped by objects.
In Cryengine I have used:

Code: Select all

Entity.Physics.Velocity = Velocity; //This works but ignores collision in a way. I cant use impulse since it doesn't behave like a FPS and behaves more like a ball game.
Also in order to rotate the control rotation in unity I would do:

Code: Select all

Velocity = Transform.Rotation * Velocity; //This rotates the velocity to the entity's direction so the directional keys match with the rotation of the player.
In Cryengine:

Code: Select all

Velocity = Entity.Rotation * Velocity; //Not sure if it works though.
So my question is, how can I assign my velocity variable into the entity and make collision also not be ignored (Is there a CharacterController.Move statement?.
Is the way I set the control rotation correct?

Re: C# Movement Help

#3
It depends on how you Physicalize your entity. The exposed properties there are in 5.3.3 are Impulse and Velocity which will work on all entities that are Rigid (Living and WheeledVehicle inherit from Rigid).

Code: Select all

//This will set the Velocity of the rigid entity Entity.Physics.Velocity = direction * moveSpeed * frameTime;
.

You can however also physicalize your entity as Living, which requires a few more settings. Here's an example how it can be achieved (converted from the C++ ThirdPerson template)

Code: Select all

private void PhysicalizeLiving() { var entity = Entity; var physics = entity.Physics; if(physics != null) { var parameters = new Common.SEntityPhysicalizeParams(); parameters.type = (int)Common.pe_type.PE_LIVING; parameters.mass = Mass; //PE_LIVING requires player-dimensions and player-dynamics to physicalize itself. var playerDimensions = new Common.pe_player_dimensions(); var playerDynamics = new Common.pe_player_dynamics(); #region Player dimensions // Set this to 0 for a cylinder shaped collider, or 1 for a capsule shape. playerDimensions.bUseCapsule = 1; // Change this to specify the size of your cylinder/capsule playerDimensions.sizeCollider = new Common.Vec3(0.45f, 0.45f, 0.45f); // Keep pivot at the player's feet (defined in player geometry) playerDimensions.heightPivot = 0.0f; // Offset collider upwards playerDimensions.heightCollider = 1.0f; playerDimensions.groundContactEps = 0.004f; parameters.pPlayerDimensions = playerDimensions; #endregion #region Player dynamics playerDynamics.kAirControl = 0.0f; playerDynamics.mass = Mass; parameters.pPlayerDynamics = playerDynamics; #endregion physics.Physicalize(parameters); } }
Once you've physicalized it as living you can use the pe_action_move to move your character. This works like this:

Code: Select all

Entity.Physics.Action((Common.pe_action_move action) => { action.dir = direction * movementSpeed * frameTime; // iJump needs to be 2 for normal movement. You can also set it to 1 which will make the movement instant instead of adding it to velocity. action.iJump = 2; });
And for what concerns the rotation of the direction you can multiply a Vector3 with a Quaternion. But in my experience I've noticed that I would often need to inverse the Quaternion to get the desired transformation. So it would look like this:

Code: Select all

Velocity = Entity.Rotation.Inverted * Velocity;
Sadly I'm no expert in Quaternions so I'm not sure if this is a bug or intentional. One thing to note is that Entity.Rotation would be Transform.LocalRotation in Unity. In the CRYENGINE the Rotation and Position properties refer to the local rotation and position instead of the world rotation and position.

Who is online

Users browsing this forum: No registered users and 2 guests