Simple Raycast Script

erayzesen

Member
itch_cover.png
Hi all. I released a raycast code to use your any projects;

Note: It support Game Maker Studio v2.3 and new versions;

Check it out: (with online demo): https://erayzesen.itch.io/simple-raycast

The method;
GML:
var rc_data=raycast(_x,_y,_dir,_length,_per_pixel,_object,_tilemap_layer_name,_precise_mode);
It return a raycast data struct, you may get results with this way;
GML:
//To get the returned raycast type
rc_data.type // rc_type.nothing , rc_type.object , rc_type.tilemap
//To get the returned instance id or tilemap index
rc_data.index
//To get returned collision positions
rc_data.x
rc_data.y
FEATURES
  • It support a specific object, multiple objects, tilemap layers or all at the same time.
  • It may work with different collision shapes. ( Set to _precise_mode as true to do that.)
  • I added comments in the script if you want to learn how it works.
  • One script file and one method.
  • Flexible to use in all your projects.

I hope you like it. Cheers.
 

kburkhart84

Firehammer Games
Purchased...I'm sure I could put something together myself but if this one works as it should it saves time(which is how assets, etc... are supposed to work ;) ).
 
Hello, I had just purchased your Raycast script, thank you for this. I was wondering how I can get the name/Id of an object that collides with the raycast. All I know is rc_data.index which returns a number. Thank you
 

chamaeleon

Member
Hello, I had just purchased your Raycast script, thank you for this. I was wondering how I can get the name/Id of an object that collides with the raycast. All I know is rc_data.index which returns a number. Thank you
The person you want an answer for has not been active for a few months, so you might not get an answer in a timely manner just posting here. However, seems like the index is the instance id, so use that in any way you require. You can do rc_data.index.object_index to get the object of the instance. Caveat, I don't have this asset, I'm only going by what this thread contains.
 

erayzesen

Member
Hello, I had just purchased your Raycast script, thank you for this. I was wondering how I can get the name/Id of an object that collides with the raycast. All I know is rc_data.index which returns a number. Thank you
Sorry I haven't entered the forum for a long time. I was waiting questions in the itch page. But @chamaeleon's answer is correct.
 
Last edited:
Top