Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: EDIT: New/simmilar request (Enemy facing view, outstretching cones)  (Read 3478 times)

0 Members and 1 Guest are viewing this topic.
EDIT: New/simmilar request (Enemy facing view, o...
« on: December 05, 2013, 02:09:18 am »
  • *
  • Reputation: +2/-0
  • Offline Offline
  • Gender: Male
  • Posts: 269
Hello all, so im in the midst of coding an enemy for game maker. (the zola from the original zelda) he has 4 basic directions and when link hits a certain point near the enemy or whatever it calculates whether the version will be right, left, up, or down, as the zolas pop out, shoot, and go back down without changing directions. so what i was thinking as a better system then the one i have is something like a triangular view box, like the picture below. but im not sure how to do that, as each box has one constant
Link.y > y
Link.y < y
Link.x > x
Link.x < x

that sets it apart from the other boxes, but then there is that gray area when the triangle outstretches. and thats where i need a different code then a simple if Link.y > y part, and im honestly lost on what to do. what would be a way to go about this? The triangles all seem equal, and form a square and seem like 45, 45, 90 triangles if that helps anything, but i dont think going the geometry route is the easiest way to solve this.

reference picture:

« Last Edit: December 07, 2013, 01:35:10 am by Whitay »
Logged

Jeod

Team Dekunutz, Doubleteam
Re: Enemy facing view, outstretching cone.
« Reply #1 on: December 05, 2013, 02:30:26 am »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1675
I don't get what you're asking. The hitbox is already a triangular view. If Link is above the Zora, or Link.y > Zora.y, then the Zora will face up. But then the code checks if Link.x > Zora.x. If it is, then the Zora will face right.

You don't need to change your code, but you need to check what comes first. Y coordinate should be checked before X.
Logged
"You should challenge your fates. When all else fails, you can still die fighting." ~Yune
___________________________________

Zelda GBC+ Engine for Multimedia Fusion 2
  • Doubleteam Project Page
Re: Enemy facing view, outstretching cone.
« Reply #2 on: December 05, 2013, 02:45:22 am »
  • *
  • Reputation: +2/-0
  • Offline Offline
  • Gender: Male
  • Posts: 269
but that wouldnt make them equal. that would work somewhat, but it would have to be very precise to face left or right. i want it to check in the view shown in the picture. the enemy is the white block, and the different colored sections are the left right etc. so if link was in the red the zora would face up. this doesnt work if i just use the simple if link.y > y and x< whatever because it will always make the hitbox on one direction very very precise. Im asking for help on a segment of code that will sort of send out
if link.y > y
{
if link. x is in that red reigon than face up
if link.x is in the side reigons face to left/right
}

if link.y < y
{
if link.x is in the sides, face to the left/right
if link.x is in the yellow, face down.
}

so yes i have to check y and then check x, but there is more too it as sometimes x components can be shared in either but also y components can be shared in either, but never both.

EDIT:
Like this picture, they can all share an x component(10 back) and they all can share a y component(10 down)
but only one can have 10 back and 10 down as a coordinate in their region.



It also seems that the x and y have to equal, like if you are 10 over you have to be 10 down to be in one region, you cant be 12 down because that is in the lowest region
« Last Edit: December 05, 2013, 02:51:16 am by Whitay »
Logged

Jeod

Team Dekunutz, Doubleteam
Re: Enemy facing view, outstretching cone.
« Reply #3 on: December 05, 2013, 02:50:47 am »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1675
In the red and green tiangles, Link.x is always > Link.y.

In the purple and yellow triangles, Link.x is always < Link.y.

Use that as a base. You have two pairs of triangles now. You need to split those two pairs up.
« Last Edit: December 05, 2013, 02:52:43 am by Jeod »
Logged
"You should challenge your fates. When all else fails, you can still die fighting." ~Yune
___________________________________

Zelda GBC+ Engine for Multimedia Fusion 2
  • Doubleteam Project Page
Re: Enemy facing view, outstretching cone.
« Reply #4 on: December 05, 2013, 02:53:03 am »
  • *
  • Reputation: +2/-0
  • Offline Offline
  • Gender: Male
  • Posts: 269
EDIT: disregard, this was before i saw your newest post
The center of the zora is the white square, so in the red it can go negative for x, and the green can go negative for y. same with yellow and purple, as yellow can go positive or negative for y and in purple you can have a positive or negative x


EDIT: i see what you are doing, but what my question is and orginally was is how would i split them up?

would something like this give it enough separation
Code: [Select]
if link.x > link.y
{
in purple zone = false
in yellow zone = false

if link.x < zora.x
{
in green zone = true
}

if link.x < zora.x
{
in red zone = true
}
}
« Last Edit: December 05, 2013, 02:58:52 am by Whitay »
Logged

Jeod

Team Dekunutz, Doubleteam
Re: Enemy facing view, outstretching cone.
« Reply #5 on: December 05, 2013, 02:59:49 am »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1675
Have you tried slope formula?

m = (y1 - y2) / (x1 - x2)
Logged
"You should challenge your fates. When all else fails, you can still die fighting." ~Yune
___________________________________

Zelda GBC+ Engine for Multimedia Fusion 2
  • Doubleteam Project Page
Re: Enemy facing view, outstretching cone.
« Reply #6 on: December 05, 2013, 03:00:29 am »
  • *
  • Reputation: +12/-2
  • Offline Offline
  • Gender: Male
  • Posts: 4849
There is a way to "cheat":

Have the Zola move toward Link at a speed of 0.  This will set a directional angle that is standard in Game Maker - direction.

Code - move_towards_point(Link.x, Link.y, 0);
or you can drag and drop the Move Towards action and use Link.x Link.y and speed 0.  Of course, the most optimum way if you do not have Link centered(origin no centered) you should do some math to get the center of Link.

Then, you have a check for the angle:
if (direction < 45 || direction >= 315)
{
      facing = right;  //or whatever your code is to make the zola face right
}
if (direction >= 45 && direction < 135)

       facing = up;
}
if (direction >= 135 && direction < 225)
{
       facing = left;
}
if (direction >= 225 && direction < 315)
{
        facing = down;
}


Now you can put those checks in either the STEP Event or if you only want it to do this when it appears, put it in the creation code after you get the direction variable that way it gets the direction once.

or you could have it keep looking (moving) at Link until it finally shoots.

It's upto you.

I hope this makes sense.  I just spent almost 10 hours changing automotive batteries, tires, and doing oil changes so my brain my be fried a bit.
Logged
  • Super Fan Gamers!

Jeod

Team Dekunutz, Doubleteam
Re: Enemy facing view, outstretching cone.
« Reply #7 on: December 05, 2013, 03:02:30 am »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1675
There is a way to "cheat":

Have the Zola move toward Link at a speed of 0.  This will set a directional angle that is standard in Game Maker - direction.

Code - move_towards_point(Link.x, Link.y, 0);
or you can drag and drop the Move Towards action and use Link.x Link.y and speed 0.  Of course, the most optimum way if you do not have Link centered(origin no centered) you should do some math to get the center of Link.

Then, you have a check for the angle:
if (direction < 45 || direction >= 315)
{
      facing = right;  //or whatever your code is to make the zola face right
}
if (direction >= 45 && direction < 135)

       facing = up;
}
if (direction >= 135 && direction < 225)
{
       facing = left;
}
if (direction >= 225 && direction < 315)
{
        facing = down;
}


Now you can put those checks in either the STEP Event or if you only want it to do this when it appears, put it in the creation code after you get the direction variable that way it gets the direction once.

or you could have it keep looking (moving) at Link until it finally shoots.

It's upto you.

I hope this makes sense.  I just spent almost 10 hours changing automotive batteries, tires, and doing oil changes so my brain my be fried a bit.

Better than I did. My last math class was two years ago.
Logged
"You should challenge your fates. When all else fails, you can still die fighting." ~Yune
___________________________________

Zelda GBC+ Engine for Multimedia Fusion 2
  • Doubleteam Project Page
Re: Enemy facing view, outstretching cone.
« Reply #8 on: December 05, 2013, 03:04:28 am »
  • *
  • Reputation: +12/-2
  • Offline Offline
  • Gender: Male
  • Posts: 4849

Better than I did. My last math class was two years ago.

Meh, I never forget the shortcuts.  I always forget the "legit" way of doing things.  xD
Logged
  • Super Fan Gamers!
Re: Enemy facing view, outstretching cone.
« Reply #9 on: December 05, 2013, 03:07:37 am »
  • *
  • Reputation: +2/-0
  • Offline Offline
  • Gender: Male
  • Posts: 269
There is a way to "cheat":

Have the Zola move toward Link at a speed of 0.  This will set a directional angle that is standard in Game Maker - direction.

Code - move_towards_point(Link.x, Link.y, 0);
or you can drag and drop the Move Towards action and use Link.x Link.y and speed 0.  Of course, the most optimum way if you do not have Link centered(origin no centered) you should do some math to get the center of Link.

Then, you have a check for the angle:
if (direction < 45 || direction >= 315)
{
      facing = right;  //or whatever your code is to make the zola face right
}
if (direction >= 45 && direction < 135)

       facing = up;
}
if (direction >= 135 && direction < 225)
{
       facing = left;
}
if (direction >= 225 && direction < 315)
{
        facing = down;
}


Now you can put those checks in either the STEP Event or if you only want it to do this when it appears, put it in the creation code after you get the direction variable that way it gets the direction once.

or you could have it keep looking (moving) at Link until it finally shoots.

It's upto you.

I hope this makes sense.  I just spent almost 10 hours changing automotive batteries, tires, and doing oil changes so my brain my be fried a bit.

oh wow i never thought of going at it from a direction(no awful pun intended) like that, that really is a shortcut! i thought the only probable way i was going to get this is with some stupid geometry stuff, but i think this should work. thanks!
Logged
Re: Enemy facing view, outstretching cone.
« Reply #10 on: December 07, 2013, 01:34:02 am »
  • *
  • Reputation: +2/-0
  • Offline Offline
  • Gender: Male
  • Posts: 269
EDIT: i have a new request thats very simmilar to this one, so i thought i would just kinda post it in here.. So i finished my zola codes and then moved on to the next enemy that i wanted to code. the beamos towers. now with this i tried to follow the direction idea the zola had, where if link was in a certain direction range ihttp://zfgc.com/forum/Smileys/tplink/kiss.gift would do something. now i had to edit it, and i came up with something like this.
Code: [Select]
move_towards_point(Link.x,Link.y,0)
///direction = point_direction(Beamos.x,Beamos.y+20,Link.x,Link.y)
if distance_to_object(Link) < 100 ///and image_speed > 0
{


if (direction > 247.5 and direction < 292.5) ///and image_index = 0
{
image_speed = 0
alarm[1] = 25
image_index = 0
}
and basically the same code for 6-7 more frames.
my original intent was if it was in a certain frame and link ran into its view, it would freeze, and then activate all its other events and such. but this wasnt working, so i got rid of all the image_index so when i stepped in it would point the direction i was in. now that worked decently well except one direction(image_index = 6) just didnt appear at all. later i tested the whole code(even though one direction wouldnt work) by adding the image_index restrictions, and it all worked, except image_index = 0 for some reason would not lock on(and 6 already didnt work.) So im wondering if im doing something wrong with directions or something, so if someone could look at my code below and help me out. Ill post the whole code in a spoiler below, as well as the sprite im using.
CODE:
Code: [Select]


move_towards_point(Link.x,Link.y,0)
///direction = point_direction(Beamos.x,Beamos.y+20,Link.x,Link.y)
if distance_to_object(Link) < 100 ///and image_speed > 0
{


if (direction > 247.5 and direction < 292.5) ///and image_index = 0
{
image_speed = 0
alarm[1] = 25
image_index = 0
}

if (direction > 202.5  and direction < 247.5) ///and image_index = 1
{
image_speed = 0
alarm[1] = 25
image_index = 1
}

if (direction > 157.5  and direction < 202.5) ///and image_index = 2
{
image_speed = 0
alarm[1] = 25
image_index = 2
}

if (direction > 112.5  and direction < 157.5) ///and image_index = 3
{
image_speed = 0
alarm[1] = 25
image_index = 3
}

if (direction > 67.5  and direction < 112.5) ///and image_index = 4
{
image_speed = 0
alarm[1] = 25
image_index = 4
}

if (direction > 22.5  and direction < 67.5) ///and image_index = 5
{
image_speed = 0
alarm[1] = 25
image_index = 5
}

if (direction > 337.5  and direction < 22.5) ///and image_index = 6
{
image_speed = 0
alarm[1] = 25
image_index = 6
}

if (direction > 292.5  and direction < 337.5) ///and image_index = 7
{
image_speed = 0
alarm[1] = 25
image_index = 7
}



}

http://z9.invisionfree.com/LOZ_OOT2D_CP/index.php?showtopic=80
Logged
Re: EDIT: New/simmilar request (Enemy facing vie...
« Reply #11 on: December 07, 2013, 06:37:21 am »
  • *
  • Reputation: +12/-2
  • Offline Offline
  • Gender: Male
  • Posts: 4849
if (direction > 337.5  and or direction < 22.5) ///and image_index = 6
{
image_speed = 0
alarm[1] = 25
image_index = 6
}

That should solve the reason why 6 wasn't working.  A number cannot be greater than 337 AND be lower than 22.  It's impossible.  You need an OR or || check for that frame.
Logged
  • Super Fan Gamers!
Re: EDIT: New/simmilar request (Enemy facing vie...
« Reply #12 on: December 07, 2013, 05:47:57 pm »
  • *
  • Reputation: +2/-0
  • Offline Offline
  • Gender: Male
  • Posts: 269
That fixed it, so thank you again. but im just wondering, why cant you have it like that? since its a 360 degree circle, isnt it possible to be less than 22 and greater than 337?
Logged
Re: EDIT: New/simmilar request (Enemy facing vie...
« Reply #13 on: December 08, 2013, 05:05:28 am »
  • *
  • Reputation: +12/-2
  • Offline Offline
  • Gender: Male
  • Posts: 4849
That fixed it, so thank you again. but im just wondering, why cant you have it like that? since its a 360 degree circle, isnt it possible to be less than 22 and greater than 337?
You cant have a real number be less than a small number but greater than a big number.  It's like that told saying: it's above your head and below your knees. 

3 cannot be less than 22 AND be greater than 320.  It's a mathematical impossibility.  It can be less than OR greater than.
Logged
  • Super Fan Gamers!
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.037 seconds with 62 queries.