add physX colliders ,add trigger, colliders now can visible, some rotation for cs and native cpp connection

This commit is contained in:
2025-12-24 10:10:24 +08:00
parent 00d3993a77
commit f747db4e27
44 changed files with 2322 additions and 860 deletions

View File

@ -22,9 +22,11 @@ namespace Example
private bool Colliding => m_CollisionCounter > 0;
private TransformComponent m_Transform;
void OnCreate()
{
m_PhysicsBody = GetComponent<RigidBodyComponent>();
m_Transform = GetComponent<TransformComponent>();
MeshComponent meshComponent = GetComponent<MeshComponent>();
m_MeshMaterial = meshComponent.Mesh.GetMaterial(0);
@ -32,6 +34,8 @@ namespace Example
AddCollisionBeginCallback(OnPlayerCollisionBegin);
AddCollisionEndCallback(OnPlayerCollisionEnd);
AddTriggerBeginCallback(OnPlayerTriggerBegin);
AddTriggerEndCallback(OnPlayerTriggerEnd);
}
void OnPlayerCollisionBegin(float value)
@ -44,6 +48,16 @@ namespace Example
m_CollisionCounter--;
}
void OnPlayerTriggerBegin(float value)
{
Console.WriteLine("Player trigger begin");
}
void OnPlayerTriggerEnd(float value)
{
Console.WriteLine("Player trigger end");
}
void OnUpdate(float ts)
{
float movementForce = HorizontalForce;
@ -53,22 +67,18 @@ namespace Example
movementForce *= 0.4f;
}
Vec3 forward = GetForwardDirection();
Vec3 right = GetRightDirection();
Vec3 up = GetUpDirection();
if (Input.IsKeyPressed(KeyCode.W))
m_PhysicsBody.AddForce(forward * movementForce);
m_PhysicsBody.AddForce(m_Transform.Forward * movementForce);
else if (Input.IsKeyPressed(KeyCode.S))
m_PhysicsBody.AddForce(forward * -movementForce);
m_PhysicsBody.AddForce(m_Transform.Forward * -movementForce);
if (Input.IsKeyPressed(KeyCode.D))
m_PhysicsBody.AddForce(right * movementForce);
m_PhysicsBody.AddForce(m_Transform.Right * movementForce);
else if (Input.IsKeyPressed(KeyCode.A))
m_PhysicsBody.AddForce(right * -movementForce);
m_PhysicsBody.AddForce(m_Transform.Right * -movementForce);
if (Colliding && Input.IsKeyPressed(KeyCode.Space))
m_PhysicsBody.AddForce(up * JumpForce);
m_PhysicsBody.AddForce(m_Transform.Up * JumpForce);
if (Colliding)
m_MeshMaterial.Set("u_AlbedoColor", new Vec3(1.0f, 0.0f, 0.0f));