Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / ObjectRayCast question?

Author
Message
Golelorn
8
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 19th Jun 2019 21:17
I thought I had this figured out, but I keep getting inconsistent results. Or perhaps, I have forgotten what I learned, since I haven't messed with this command in awhile.

If I do ObjectRayCast(1,x,y,z,nx,ny,nz) Shouldn't it return a 0 if there is another object between the ray? Or is this only testing to see if the one object is in the ray path?

Conversely, if I send out a ray of ObjectRayCast(0,x,y,z,nx,ny,nz) should it not return the first object hit? Instead I get the object hit at the end of the ray, and the object in-between is only hit if I put that object ID in(so I know its not a case of me inadvertently turning off collision mode).

I could have sworn I have mentioned this before, but the documentation is wrong. ObjectRayCast() only returns a 1 if you put in the ObjectID.

Doc page

Quote: "will return the number of the object hitt first, or 0 for no collision"


Would be nice to get that fixed.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 20th Jun 2019 02:05
The easiest way to raycast I find is to check for object collision with the below function

fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 20th Jun 2019 23:33 Edited at: 20th Jun 2019 23:34
If it isn't returning the first object hit, then yeah that's probably a bug.

I did notice this in the docs though as a work around:



Looks like if multiple objects are hit, it keeps a list of all of them that you can scan through.

If it's actually returning the last object hit instead of the first, then possibly you just want the hit at the other end of the list...
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
Golelorn
8
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 21st Jun 2019 15:29
Thanks, Ortu. I will see if that is the case.
Bryan Ruffin
5
Years of Service
User Offline
Joined: 16th Apr 2019
Location:
Posted: 27th Jun 2019 07:20
I high appreciate this post. It’s hard to find the good from the bad sometimes, but I think you’ve nailed it! would you mind updating your blog with more information?
geometry dash

Login to post a reply

Server time is: 2024-11-21 12:41:04
Your offset time is: 2024-11-21 12:41:04