This project has moved and is read-only. For the latest updates, please go here.

Will Someone Please Explain RayCasting?

Topics: User Forum
Jun 6, 2013 at 4:39 AM
I'd like to use raycasting for a number of things for my game, most notably to check if my player is colliding with the floor though. I've looked at the testbed example for using raycasting and i somewhat get it, but the actual function confuses me. i dont know what the => operator is, and i dont understand what exactly world.raycast is supposed to return.
Jun 14, 2013 at 4:46 PM
The '=>' is an operator that indicates the beginning of an anonymous method. Usually the World.Raycast() function takes in a delegate that you would like to run against all the objects in the world that the ray intersects. Instead of making a named method like this:

private void MyMethod(Fixture f)
{ }

you simply do this:

f => { }

As you can see, it does not have a name, it only takes in 'f', which is a Fixture. For more info, read up on anonymous methods in C#.
Jun 14, 2013 at 7:17 PM
thank you genbox, i have already gotten raycasting working for checking collision with the ground, walls and walljumping, and even implemented a grapple system using raycasting and distance joints :)