Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Add impulse information to Stride.Physics.ContactPoint #2490

Open
Oberon-Zheng opened this issue Oct 18, 2024 · 0 comments
Labels
area-Physics enhancement New feature or request

Comments

@Oberon-Zheng
Copy link

Oberon-Zheng commented Oct 18, 2024

As Stride API indicated, Stride.Physics.ContactPoint gets collision information in simulation via an internal method LatestContactPointsFor(), in which ContactPoint obtains the contact data in a buffer and returned with Bullet Native API (to be elaborative, it's from btManifoldPoint/ManifoldPoint in BulletSharp).

for (int j = 0; j < numContacts; j++)
{
var point = BulletSharp.ManifoldPoint.FromPtr(btPersistentManifold_getContactPoint(persManifoldPtr, j));
buffer.Add(new ContactPoint
{
ColliderA = collA,
ColliderB = collB,
Distance = point.m_distance1,
Normal = point.m_normalWorldOnB,
PositionOnA = point.m_positionWorldOnA,
PositionOnB = point.m_positionWorldOnB,
});
}
}

Since it's found that Stride ContactPoint provides limited contact info about collider, normalvec, distance and point pos. But other game engines can also provide the impulse of contact (e.g., in Unity, we can get this via ContactPoint.impulse field, in Godot we can find this via get_contact_impulse of PhysicsServer), which is missing in Stride API but actually supported in BulletSharp.ManifoldPoint (point.m_appliedImpulse).

public struct ContactPoint : IEquatable<ContactPoint>
{
public PhysicsComponent ColliderA;
public PhysicsComponent ColliderB;
public float Distance;
public Vector3 Normal;
public Vector3 PositionOnA;
public Vector3 PositionOnB;
public bool Equals(ContactPoint other)
{
return ((ColliderA == other.ColliderA && ColliderB == other.ColliderB)
|| (ColliderA == other.ColliderB && ColliderB == other.ColliderA))
&& Distance == other.Distance
&& Normal == other.Normal
&& PositionOnA == other.PositionOnA
&& PositionOnB == other.PositionOnB;
}
public override bool Equals(object obj) => obj is ContactPoint other && Equals(other);
public override int GetHashCode()
{
return HashCode.Combine(ColliderA, ColliderB, Distance, Normal, PositionOnA, PositionOnB);
}
}

AFAIAC, sometimes this impulse information is useful for physics interaction manipulation, so it's probably necessary reasonable to provide this in ContactPoint since the underlying Bullet body is literally not accessible directly as internal member of RigidbodyComponent.

@Oberon-Zheng Oberon-Zheng added the enhancement New feature or request label Oct 18, 2024
@Oberon-Zheng Oberon-Zheng changed the title Add impulse information to Stride.Physics.ContactPoint [Feature Request] Add impulse information to Stride.Physics.ContactPoint Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Physics enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants