June 2018
Beginner to intermediate
298 pages
7h 38m
English
Because the characters are moving on a grid, they need to either move the full distance to the next tile or not at all. This means that, before moving, the character needs to check to see if the move is possible. One way to test if an adjacent square has anything in it is by using a raycast. Raycasting means extending a ray from the character's position to a given destination. If the ray encounters any object along the way, it will report that contact. By adding four rays to the character, it can look at the squares around it to see if they are unoccupied.
Add four RayCast2D nodes and set their names and Cast To properties as follows:
| Name | Cast To |
| RayCastRight | (64, 0) |
| RayCastLeft | (-64, 0) |
| RayCastDown | (0, 64) |
Read now
Unlock full access