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 / Raycasting for enemy logic (2d game)

Author
Message
Thomas John Gorham
5
Years of Service
User Offline
Joined: 23rd Jun 2018
Location:
Posted: 23rd Oct 2020 08:12
Hi guys,

Im working on another enemy in my game, its a gun with legs.

Anyway, im hoping to use some sort of raycasting, id like to draw a ray between the enemy sprite and the player. I was wondering if there was a command that returns the value of the FIRST sprite that gets hit by the line. Then you can see if an Enemy has the player in its line of sight, or if its blocked by a crate or a wallsprite.

What are the commands to use for something like this? Is this already how it works?

Also, how would you set sprites to not return values if they are hit (for example, floor tiles shouldnt count)

Thanks in Advance
Thomas
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 23rd Oct 2020 08:35 Edited at: 23rd Oct 2020 09:31
Quote: "Is this already how it works? "

yes. see SpriteRayCast() , SpriteRayCastGroup() and:
[My Itch.io Home] [#LowRezJamAGK2020]
[AGK Resource Directory] [TGC @ GitHub]
[CODE lang=AGK] YOUR CODE HERE [/CODE]
[VIDEO=youtube] VIDEO ID [/VIDEO]
[Google Forum Search]
Thomas John Gorham
5
Years of Service
User Offline
Joined: 23rd Jun 2018
Location:
Posted: 23rd Oct 2020 09:43
Dude your like my personal AppGameKit coach now! Thanks

Ive added all my destructables, player, enemies, and wall in one group.

projectiles, floor, dead enemies and broken destructables in another!

its checking for visibility of the player and working!

ThankyoU!
Thomas John Gorham
5
Years of Service
User Offline
Joined: 23rd Jun 2018
Location:
Posted: 28th Nov 2020 04:00
Hey guys,

does the Raycasting features work of the bounding box shapes defined by setspriteshape? I am having trouble getting my enemy to shoot when im standing next to a wall.
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 28th Nov 2020 05:55 Edited at: 28th Nov 2020 06:23
are you just aiming for the center? consider shooting at the "head" if the player is below then enemy, "feet" otherwise? then, pick a "side" based of above/below? i think you'll need to add this bit of "realism" re: LOS.

that wasn't sound advice... so, i tried shooting at both:

...and, something's wrong there, too. i think the rays are hitting each other?

i might be a coach, but we'll need a general manager for this one
[My Itch.io Home] [Now Playing]
[AGK Resource Directory] [TGC @ GitHub]
[CODE lang=AGK] YOUR CODE HERE [/CODE]
[VIDEO=youtube] VIDEO ID [/VIDEO]
[Google Forum Search]

Login to post a reply

Server time is: 2024-03-29 11:00:12
Your offset time is: 2024-03-29 11:00:12