2D perfect collisions on fast, player controlled movement.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By sian2005

Hello there,

I have a problem, I have a pickaxe in the players hand that rotates accordingly to the mouse.
I get the collisions using 2 RayCasts on both ends of the pickaxe.
I do this so that I can’t move it inwards more, but if the second raycast isnt colliding I can pull it out again.
But when you rotate/move the pickaxe too fast, it will clip too far in the wall, and the second end also collide with the wall, and so I cant move/rotate it out again…

Is there any answer to let the pickaxe stop exactly on the wall/floor?
That would be awesome.

(I’m a not that experienced programmer yet, just so you know)

Kind regards, sian2005

:bust_in_silhouette: Reply From: Merlin1846

Simply give the pickaxe a collision body.

That doesnt work with the rotation, I have tried that before…

sian2005 | 2020-03-29 17:04

:bust_in_silhouette: Reply From: lucaslcode

I think you need more raycasts.

Maybe something like, if the pickaxe is going to rotate more than a certain amount, split it into two or more segments, and do a raycast in code for each segment to check if it is colliding, and if so, move it to the collision point.

Some info on code ray-casting here.