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.

AppGameKit Classic Chat / Which ray cast to see player?

Author
Message
Psycho Psam
16
Years of Service
User Offline
Joined: 3rd Apr 2008
Location: Western Australia
Posted: 19th Nov 2013 16:29
I'm using sprites and I have a maze. I want to use a ray cast to see if the player can be seen but PhysicsRayCast and SpriteRayCast return 1 or 0. I really need to see which sprite got hit.

How would I do that? All I can think to do is cast a ray from my enemy x,y to the player x,y and hide the player. Then if the ray returns 0 it got through to the player.

Is there a ray to see which object got hit?
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 19th Nov 2013 16:57
I think you might be able to do:

Col=SpriteRayCast(....

Then Col would be the closest sprite to the original start location that is hit. You can probably get the number of hits, location, maybe even bounce vectors - but for detecting if the player is visible or not, the simple ray cast should be fine.

Might be interesting to mix up the ray cast check though, like checking the player position with a random offset, so long as the offset stays within the player sprite, you can add some chance to whether or not you got spotted, but also increase the accuracy.

Like, say the player is 49% visible around a corner, with a straigt collision check, the player would be regarded as hidden, because from the centre of the player sprite to the enemy is a straight an unchanging line. But, if you add a random offset, then theres's probably a 49% chance that the player will be seen, or be seen half as quickly as they would being fully visible. See, the random offset means sometime the offset position will be visible, and sometimes not. With just a little randomness, you'd end up with more realism - if the player is well hidden, like maybe only 5% visible, then it would take 20 times longer, 20 times more checks before the enemy would find them. So long as you don't check for visibility every loop, I think you'd notice the difference with the offset.

I would do something similar in 3D, like check the ray cast between an enemies eyes and a random bone position on a model - this technique is kinda free in terms of performance, and less prone to abuse I think. Sometimes I just sit and wonder why so many AI systems are so stupid and predictable - mix it up a bit - one thing is for sure, AI that is too calculated and precise is boring, a little random behavior here and there can turn that into fascinating

I am the one who knocks...
Psycho Psam
16
Years of Service
User Offline
Joined: 3rd Apr 2008
Location: Western Australia
Posted: 20th Nov 2013 00:15
Thanks for the awesome explanation and ideas. Yeah I agree with you on AI in games. It really makes me think that AI programmers are just normal people with a huge burden of getting their job done in time so the game ships. Deux Ex (the reboot) showed me that even the top AI programmers don't really know how to do it properly. For example I'm in a fire fight, one guy comes out. I shoot him and he runs back then. Then he comes out again and I shoot him. Then I got into where his mates are and they have no idea I've been outside all the time shooting the place up. Very dumb AI.
Psycho Psam
16
Years of Service
User Offline
Joined: 3rd Apr 2008
Location: Western Australia
Posted: 21st Nov 2013 08:54
I've tried this out and this doesn't return the closest sprite it just returns 1 or 0. Is there a command that returns the first sprite hit?
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 21st Nov 2013 09:12
I'm sure there is - but I don't have AppGameKit handy right now, I will check and get back to you later.

I am the one who knocks...
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 21st Nov 2013 15:18
GetRayCastSpriteID() returns the ID of the sprite hit in the most recent ray cast check. If the ray hit a non-sprite shape 0 will be returned.

I'm guessing that the RayCast stops as soon as it hits anything, based on the help for the various other commands.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Psycho Psam
16
Years of Service
User Offline
Joined: 3rd Apr 2008
Location: Western Australia
Posted: 22nd Nov 2013 09:59
Thanks Ancient Lady. That will work

Login to post a reply

Server time is: 2024-05-03 10:43:22
Your offset time is: 2024-05-03 10:43:22