Creating triggers in C# between 2 points

So I am making my first 2D platformer in unity using C#, and have noticed that collision is not detected between frames, meaning if my fps was 1, I could walk through walls, which is not what I want. To fix this I want to make it so that a point follows the player, updating every frame. The idea is that the point will draw a line to the player, and if that line intersects a given object such as the floor or a wall, it will translate the player’s position to the point instead of the point translating to the player.
Problem is, I don’t know how to create a line (or thin box would work I guess) between 2 points that acts as a trigger in C# script.

Is there a better way of doing this because if so I would appreciate that, although it would be useful to know how to create triggers anyway.

Thanks a lot guys.

Are you doing all of your movement in FixedUpdate? This problem normally only occurs with very thin colliders at very high speeds.

The general way to do this is to raycast between the old position and the new one. I believe there is a script on the wiki called DontGoThroughThings that you can use as a base.

No, all movement and whatnot is in Update, being called every frame. I set a velocity limit so it doesnt normally happen around 20ish fps, but it would be easily exploitable, not like it really matters cuz I’m the only one who will play it, but still…

Thanks though.

EDIT: Wow, this FixedUpdate thing makes a lot of things easier, while completely rendering a script I made before meaningless. Thanks though, this will make things a lot easier.

1 Like