How to move and rotate an entity with C++

Hello everyone,
I try to make a minigame and in my component I used this code for movement an entity:

Code: Select all

// Check input to calculate local space velocit if (m_inputFlags & EInputFlag::MoveForward) { velocity.y += m_moveSpeed * frameTime; } if (m_inputFlags & EInputFlag::MoveBack) { velocity.y -= m_moveSpeed * frameTime; } // Update the player's transformation Matrix34 transformation = m_pEntity->GetWorldTM(); transformation.AddTranslation(transformation.TransformVector(velocity)); // Apply set position and rotation to the entity m_pEntity->SetWorldTM(transformation);
and this code for rotation:

Code: Select all

Quat rotation = m_pEntity->GetRotation(); float dir = 0.0f; if (m_inputFlags & EInputFlag::MoveLeft) { dir = -1.0f; } if (m_inputFlags & EInputFlag::MoveRight) { dir = 1.0f; } rotation *= Quat::CreateRotationZ(DEG2RAD(m_rotationSpeed * dir) * frameTime).GetInverted(); m_pEntity->SetRotation(rotation);
It works perfectly but my entity has not collision.


Re: How to move and rotate an entity with C++

Apologies if this has been fixed.
I think The Collisions are not working because of The movement mode you are using, you are translating the entity which ignores the colliders.
Now I come from a UE4 background so, I don't really know if Cryengine does Translation differently or not but traditionally translating objects around ignores the collisions.

My solution ( again I don't know if these things exist in Cryengine or not, I am struggling to find stuff myself to learn Cryengine).

There must be a DefaultComponent or a prepackaged Component that contains PlayerController or CharacterController use that as a base. (DefaultComponents/Physics/CharacterController.h)
it should have MoveTo or something like that function that takes in a direction.
moving using CharacterControllers helps alot and is alot better approach to make games rather than code everything from scratch they have collision checks and everything.

it would be helpful if someone more experienced can tell more about this in Cryengine context.

Who is online

Users browsing this forum: No registered users and 3 guests