Problems in cryengine 5.4 physicalized

#1
Can someone tell me what is going on with the fisicalizaçao in this component.
Your help with this problem would be welcome.
In which I try to start the game and the car starts to spin to the right and then begins to float.

how can I leave the code here to help me.

Code: Select all

#include <StdAfx.h>
#include "CPlayerVehicle.h"



static void RegisterPlayerVehicleComponent(Schematyc::IEnvRegistrar& registrar)
{
Schematyc::CEnvRegistrationScope scope = registrar.Scope(IEntity::GetEntityScopeGUID());
{
scope.Register(SCHEMATYC_MAKE_ENV_COMPONENT(CPlayerVehicle));
}
}

CRY_STATIC_AUTO_REGISTER_FUNCTION(&RegisterPlayerVehicleComponent);


CPlayerVehicle::CPlayerVehicle() : m_Health(100.0f), m_fMaxSpeed(200.0f), m_cameraOffset(0.0f, -5.0f, 2.5f)
{
}

CPlayerVehicle::~CPlayerVehicle()
{
}

void CPlayerVehicle::Initialize()
{
m_pBoxPrimitiveComponent = GetEntity()->GetOrCreateComponent<Cry::DefaultComponents::CBoxPrimitiveComponent>();
m_pBoxPrimitiveComponent->m_bReactToCollisions = false;

m_pStaticMeshComponent = GetEntity()->GetOrCreateComponent<Cry::DefaultComponents::CStaticMeshComponent>();

m_pRigidBodyComponent = GetEntity()->GetOrCreateComponent<Cry::DefaultComponents::CRigidBodyComponent>();
m_pRigidBodyComponent->m_bSendCollisionSignal = true;

m_pCylinderPrimitiveComponent = GetEntity()->GetOrCreateComponent<Cry::DefaultComponents::CCylinderPrimitiveComponent>();


VehiclepInit();

}

uint64 CPlayerVehicle::GetEventMask() const
{
return BIT64(ENTITY_EVENT_UPDATE) | BIT64(ENTITY_EVENT_COLLISION);
}

void CPlayerVehicle::ProcessEvent(SEntityEvent& event)
{

}

void CPlayerVehicle::VehicleInit()
{
//"objects/testobjects/SF_Free-Fighter.cgf"
/*LoadModel("objects/arc/ARC170.cgf");*/
LoadModel("objects/Vehicles/Sports_Car_GT3/Sports_Car_GT3.cgf");

//// Box primitive component
m_pBoxPrimitiveComponent->m_size = Vec3(1.5f, 2.8f, 2.f);
Matrix34 boxComponentTM = m_pBoxPrimitiveComponent->GetTransformMatrix();
boxComponentTM.SetColumn(3, Vec3(0, 0, -0.3));
m_pBoxPrimitiveComponent->SetTransformMatrix(boxComponentTM);
m_pBoxPrimitiveComponent->m_bReactToCollisions = true;

//// ~Box primitive component

//m_pCylinderPrimitiveComponent->m_height = 0.5f;
//m_pCylinderPrimitiveComponent->m_radius = 0.2f;
//Matrix34 m_cilinder = m_pCylinderPrimitiveComponent->GetTransformMatrix();
//m_cilinder.SetColumn(3, Vec3(0.0f, 1.5f, 0.0f));
//m_cilinder.CreateRotationXYZ(Ang3(0.0f, -90.0f, 0.0f));
//m_pCylinderPrimitiveComponent->SetTransformMatrix(m_cilinder);


/*CreateGeometry();*/
// Create Weapon

CWeapon *m_Wepon1 = m_pEntity->CreateComponent<CWeapon>();
m_Wepon1->SetLocalPosition(Vec3(1.5f, 0.0f, -1.0f));
m_Weapons.push_back(m_Wepon1);

CWeapon *m_Wepon2 = m_pEntity->CreateComponent<CWeapon>();
m_Wepon2->SetLocalPosition(Vec3(-1.5f, 0.0f, -1.0f));
m_Weapons.push_back(m_Wepon2);


/*DrawPlayerName("Player");*/
Physicalized();
}


void CPlayerVehicle::VehicleEvent(SEntityEvent& event)
{
Vec3 forwardDir = GetEntity()->GetForwardDir();
GetEntity()->SetPos(GetEntity()->GetPos() + (forwardDir * m_fCurrentSpeed));
}

void CPlayerVehicle::Fire()
{
for (CWeapon *m_currenWeapon : m_Weapons)
{
m_currenWeapon->Fire();
}
}

void CPlayerVehicle::SetHealth(float health)
{
m_Health = health;
}

float CPlayerVehicle::GetHealth()
{
return m_Health;
}

float CPlayerVehicle::GetMaxSpeed()
{
return m_fMaxSpeed;
}

void CPlayerVehicle::setVelocity(Vec3 velocity)
{
m_pRigidBodyComponent->SetVelocity(velocity);
}

void CPlayerVehicle::UseHandbrake(Vec3 velocity)
{
}

Vec3 CPlayerVehicle::getVelocity()
{
return m_pRigidBodyComponent->GetVelocity();
}

Vec3 CPlayerVehicle::getCameraOffset()
{
return m_cameraOffset;
}

void CPlayerVehicle::DrawPlayerName(const char* playerName)
{
if (m_pDebugDrawComponent)
{
//Matrix34 localTM = m_pDebugDrawComponent->GetTransformMatrix();
//Vec3 localPos = localTM.GetTranslation();
//localPos.z += 2.f;
//localTM.SetTranslation(localPos);
//m_pDebugDrawComponent->SetTransformMatrix(localTM);

m_pDebugDrawComponent->SetPersistentText(playerName);
m_pDebugDrawComponent->SetPersistentTextColor(Vec3(1, 0, 0));
m_pDebugDrawComponent->SetPersistentTextViewDistance(255);
m_pDebugDrawComponent->EnablePersistentText(true);

SEntityEvent event;
event.event = ENTITY_EVENT_COMPONENT_PROPERTY_CHANGED;
m_pDebugDrawComponent->SendEvent(event);
}
}



void CPlayerVehicle::SerializeProperties(Serialization::IArchive& archive)
{
if (archive.openBlock("testvehicle", "textvehicle"))
{

archive.XML_VERSION_1;
SerializeProperties(archive);
archive.closeBlock();
}


}


void CPlayerVehicle::LoadModel(const char* modelPath)
{
// Load the ship model
m_pStaticMeshComponent->SetFilePath(modelPath);

//Cry::DefaultComponents::SPhysicsParameters &physParams = m_pStaticMeshComponent->GetPhysicsParameters();
//physParams.m_mass = 1500;
//physParams.m_density = 0;

m_pStaticMeshComponent->LoadFromDisk();
m_pStaticMeshComponent->ResetObject();
// ~Load the ship model
}

void CPlayerVehicle::Physicalized()
{
SEntityPhysicalizeParams m_parms;
m_parms.type = PE_RIGID;
m_parms.mass = 1500.0f;
m_parms.density = -1.f;

pe_player_dynamics player_dynamics;
player_dynamics.gravity = Vec3(0.0f, 0.0f, 1.0f);
player_dynamics.kAirResistance = 1.0f;
player_dynamics.kInertia = 1.0f;

m_parms.pPlayerDynamics = &player_dynamics;

m_pEntity->Physicalize(m_parms);
}
/Edit by Cry-Flare - Please use the syntax BBCode for posting code snippets in future.
Attachments
Capturar.PNG
Capturar.PNG (1.25 MiB) Viewed 775 times

Who is online

Users browsing this forum: No registered users and 4 guests

cron