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!

486 views / 16 in the last 7 days

5 votes | 0 in the last 7 days

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

open in greenfoot
Your browser does not support the canvas tag.
A new version of this scenario was uploaded on 2020-11-24 17:32:07 UTC
Duck12Duck12

2020/11/24

wow really cool.
A new version of this scenario was uploaded on 2020-11-24 20:45:24 UTC
A new version of this scenario was uploaded on 2020-11-24 20:47:20 UTC
RcCookieRcCookie

2020/11/24

Thanks a lot!
A new version of this scenario was uploaded on 2020-11-25 15:59:29 UTC
Roshan123Roshan123

2020/11/25

Wow¡¡¡¡¡ भादिया बनाया है Frm where did u learnt this all Especially about java fx...
RcCookieRcCookie

2020/11/25

Java fx? I'm not using anything but plain java for that. The actual raycast math classes dont ever need greenfoot
RcCookieRcCookie

2020/11/25

With plain java I meant no external packages
RcCookieRcCookie

2020/11/25

And in terms of the math - school. And some wikipedia.

See all comments

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

Who likes this?

Letizeus 00swinter Roshan123 Duck12 Super_Hippo