Need Help With Raycasting C#

Hey all,

I just started creating a 2D platformer game for fun. What I need help with is with my character’s jumping ability. I decided to run a raycast. If the ray cast hits the floor, which he will be standing on, he will be allowed to jump. I want this done so you aren’t allowed to double jump while in the air.
The main issue I have is being able to change the origin location of the raycast. I want to have one ray on the left side of the sprite, and another on the right side. This is so you can still jump with most of the sprite being off a platform still. Also I need to know how to check if a ray has actually hit something so I can tell the character not to jump.

Thanks in advance.

The Bounds of a sprite will tell you where the extents of the sprite are.

If you know where the center of the sprite is, you subtract half the height of the sprite to get the bottom, then add and subtract the extent in the x axis to get the right and left, respectively.

Raycast returns a bool(true/false) if it hits a collider. you’ll need a Ray, which is defined by an origin and a direction- remember that Vectors can represent both a position and a direction. You can also use a RaycastHit to put into the out parameter to get the information about where and what the ray hit.

Remember not to mix the 2D methods with the 3D methods.

While I was waiting for a response I was playing around with the kinds of things you mentioned. I remember doing this exact thing back in high school so implementing it was fairly simple to do.
Thanks for the reply.