This site requires JavaScript, please enable it in your browser!
Greenfoot back

Report as inappropriate.

RcCookie
RcCookie presents ...

2020/11/22

Raycasting demo

This is a demo of my raycasting algorithm. It is very fast (demo runs on my laptop at ~3000 fps) and completly reusable. It allows specification of start, direction, maximum distance, target class, ignored actors and more!

The algorithm works by generating the edges of each actor, removing the ones facing away from the ray and mathmatically calculating if the ray intersects each edge. This is more precise and much quicker than walking step-by-step through the world checking for intersection with each actor on every frame. It is also not neccecarily limited in distance: The collision check of an actor a million units away takes just as the one for one 1 unit away.

For additional performance all generated edges are cached meaning that non-moving actors will be even more performant.


Use in games I could think of would be for example sensors off all kinds, weather you want to simulate a light gate or want to use ai to manouver a car around a track, Also, this can be interesting when simulating vision range. Additionally it can be helpful simply for checking if there is something in the way between two objects.


Use the arrow keys to move around. The visualization is also included and reusable, but not at all neccecary!

982 views / 37 in the last 7 days

8 votes | 0 in the last 7 days

Tags: game simulation physics demo light ray collision raycast beam cast

This scenario is a member of: Reusable classes


open in greenfoot
Your browser does not support the canvas tag.
Goku555Goku555

2021/2/19

Hi
Goku555Goku555

2021/2/19

Hi
Goku555Goku555

2021/2/19

Hi
Goku555Goku555

2021/2/19

Hi
Goku555Goku555

2021/2/19

Hi
Goku555Goku555

2021/2/19

Hi
Goku555Goku555

2021/2/19

Hi
Goku555Goku555

2021/2/19

Hi
Goku555Goku555

2021/2/19

Hi
pattypablopattypablo

4 days ago

no

See all comments

Want to leave a comment? You must first log in.

Who likes this?

SPower BavarianLP MrCohen Kostya20052011 Letizeus 00swinter Duck12 Super_Hippo