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!

-- Updated to work with Java 8 --

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!

3404 views / 1706 in the last 7 days

11 votes | 1 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
pattypablopattypablo

2021/4/13

no
A new version of this scenario was uploaded on 2021-07-18 07:35:23 UTC
tomy157atomy157a

2024/3/1

yes

See all comments

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

Who likes this?

AbdulrazaqAS Roshan123 Game/maniac SPower BavarianLP MrCohen Kostya20052011 Letizeus 00swinter Duck12 Super_Hippo