I am making bullet physics through script without rigidbody using raycast and I wanna know how to implement Speculative CCD for it because bullets keep passing through at high speeds.
this is my bullet script
public class C_BaseKinematicEntity : MonoBehaviour
{
public C_BaseKinematicEntity(GameObject entity, EntityProperties_t entityProperties)
{
this.entity = entity;
this.mass = entityProperties.mass;
this.drag = entityProperties.drag;
this.angularDrag = entityProperties.angularDrag;
}
public GameObject entity;
public float drag, angularDrag, mass;
public Vector3 position, velocity, angularVelocity;
public Quaternion rotation;
public void Setup(EntityData_t entityData)
{
this.position = entityData.position;
this.rotation = entityData.rotation;
this.velocity = entityData.velocity;
this.angularVelocity = entityData.angularVelocity;
this.UpdateGameObject();
}
public void UpdateGameObject()
{
this.entity.transform.position = this.position;
this.entity.transform.rotation = this.rotation;
}
public void UpdateVelocity()
{
this.velocity += Physics.gravity * Time.fixedDeltaTime;
this.velocity *= (1 - Time.fixedDeltaTime * this.drag);
Util.Render.DebugCube(this.position + this.velocity, 0.1f, Color.grey);
}
public void UpdatePosition()
{
this.position += this.velocity * Time.fixedDeltaTime;
}
public void UpdateRotation()
{
this.rotation = Quaternion.FromToRotation(Vector3.forward, this.velocity);
}
public void UpdateCollision()
{
float maxDistance = this.velocity.magnitude * Time.fixedDeltaTime;
RaycastHit hit;
if (Physics.BoxCast(this.entity.transform.position, this.entity.transform.lossyScale / 2, this.entity.transform.forward, out hit, this.entity.transform.rotation, maxDistance))
{
ProcessCollision(hit);
}
}
public virtual void ProcessCollision(RaycastHit hit) { }
}