Current Events > Hypothetically, let's say I'm making a game in game maker

Topic List
Page List: 1
AlisLandale
04/22/21 2:17:48 AM
#1:


Now let's say, hypothetically, I am total ass poop dookie at programming

And now that we've established that I'm making a game in game maker and am ass poop dookie at programming, let's say, hypothetically, that I want an enemy to check the relative position of the player, so that it can swing a weapon in the player's general direction. The enemy, of course, can only face in the four cardinal directions.

You see, hypothetically speaking, the problem my current, simple code would have is that it prioritizes one axis, so that the enemy will only face up and down, or left and right, but never all four.

What might be some ways to address this?

Because hypothetically, I'm a dumbass.

---
... Copied to Clipboard!
Nukazie
04/22/21 2:23:59 AM
#2:


hypothetically, i would make 4 separate collision masks for each direction to detect the player

using something like collision_rectangle( x1, y1, x2, y2, obj_player, 0,1)

and with those coordinates, you can also make the detection be short/long range

---
Life is just a journey from the maternity ward to the crematorium.
... Copied to Clipboard!
Smashingpmkns
04/22/21 2:28:31 AM
#3:


It's been a while since I used GMS but Iirc correctly you can get the relative position of your player character with something like _player.x or _player.y. depending on what you want to do you're gonna have to incorporate the width of the Sprite possibly. At least I had to when I was fucking around with it. You're probably gonna have to make a script.

I recommend the Gamemaker reddit. They're super helpful there and they answer questions really fast. I also recommend checking out Shaun Spalding's vids on YT.
---
... Copied to Clipboard!
AlisLandale
04/22/21 3:12:10 AM
#4:


Thanks guys.

Its been surprisingly hard finding tutorials for this specific problem. I just found Spauldings action rpg playlist which Im gonna watch through, but the enemy chase video uses a slime sprite that only faces left and right. <_<;

Nukazies brute force idea is probably what Im gonna use in the mean time. Just found out theres a built-in, 360-degree direction variable. Since the enemy will be aggrod and moving towards the player if it needs to attack, I can probably create 4 difference cases depending on the direction it last moved towards before attacking.

(Before I was just using the players x and y position relative to the enemy, which caused the axis problem)


---
... Copied to Clipboard!
Topic List
Page List: 1