I’m adding a telescoping check on my controller’s fixed update.
Basically I’m shooting a linecast between each frame and then repositioning the player to the hit point.
That way if the player moves fast enough to make gaps between frames the line will catch it.
The only trouble I’m having is that if I don’t also zero the velocity it just picks up where it left off and doesn’t check the collision before going to the next update.
Is there a way that I can have it collide without having to zero the velocity?
//This is called every FixedUpdate();
void CheckTelescoping(){
Vector3 positionMark = new Vector3 (0,0,0);
var layerMask1 = 1 << 0;
var myLayerMask = layerMask1;
RaycastHit hit;
if (Physics.Linecast(positionMark, transform.position, out hit, myLayerMask)){
transform.position = hit.point;
myRigidbody.velocity = Vector3.zero; //This is the bit of code I want to be able to get rid of.
Debug.Log("BONK!");
}
positionMark = transform.position;
}