Edited by Darkflamewolf, 11 May 2009 - 12:25 AM.
Distance To Object X,y Values?
#1
Posted 10 May 2009 - 10:09 PM
#2
Posted 10 May 2009 - 10:22 PM
Like this:
if point_distance(x,y,Mega_Man.x,y)
#3
Posted 10 May 2009 - 10:29 PM
Thanks for the help already though! You're already pointing me in the right direciton. A demo level should be forthcoming once I get all my questions answered, then people can judge if my project is worth pursuing after that.
Edited by Darkflamewolf, 10 May 2009 - 10:30 PM.
#4
Posted 10 May 2009 - 10:34 PM
if abs(Mega_Man.x-x) <5 {
// if 5 pixles from MM's x cordinate
}
#5
Posted 10 May 2009 - 10:40 PM
#6
Posted 10 May 2009 - 10:46 PM
well the y value I don't care about, can I safely ignore it and just be (x, Mega_Man.x)? Or does it not work this way? How can I make that statement true when I simply don't care about one value? Like the y value, MM can be as close or as far away from the enemy for all I care y wise, but x wise, he can't.
Thanks for the help already though! You're already pointing me in the right direciton. A demo level should be forthcoming once I get all my questions answered, then people can judge if my project is worth pursuing after that. biggrin.gif
point_distance(x,y,Mega_Man.x,y) should only check the horizontal distance, since its checking from and to the same y value, only the x values are different.
If you tried it, did it not work?
#7
Posted 10 May 2009 - 10:50 PM
That's kind of my problem. I'm insanely new to GML but pretty coherent with Drag n Drop. So excuse my noobness when it comes to asking stupid questions about GML.
So I merely put that line of code:
if point_distance(x,y,Mega_Man.x,y)into the enemy object and then do my little
{
do stuff here
}
afterwards and everything should be fine?
Just asking how specifically its to be used? For if I want to check a 'y' variable, and not the x variable, do I merely swap the x and y positions in that statement? Thanks for the help! I'm learning!
#8
Posted 10 May 2009 - 10:50 PM
Its a mathematical term that basically changes any value into a positive value.
The absolute value of 2 is 2.
The absolute value of -5 is 5
#9
Posted 10 May 2009 - 11:07 PM
if (point_distance(x,y,Mega_Man.x,y) < 50)
{
drop bomb
}
Says, if it's less than 50 pixels away horizontally it'll drop a bomb. You can change the 50 of course. Or change it to an equal-sign or a greater than sign or anything really.
Though in this case point_distance isn't really required, you could simply write:
if (x > Mega_Man.x-25 and x < Mega_Man.x+25)
{
drop bomb
}
As you can see point_distance is a bit easier to use. Good luck!
#10
Posted 10 May 2009 - 11:14 PM
EDIT: Wait a minute, I think I'm getting it:
If I want merely the y value only, it'd be like this right?
if (point_distance(x,y,x,Mega_Man.y) < 50)
{
drop bomb
}
And for Drag n Drop purposes, I can do this all in a Var (circle) function yes?
Edited by Darkflamewolf, 10 May 2009 - 11:17 PM.
#11
Posted 10 May 2009 - 11:18 PM
In that case:
If
if (point_distance(x,y,Mega_Man.x,y) < 50)
{
drop bomb
}
is the finds the distance between x variables,
if (point_distance(x,y,x,Mega_Man.y) < 50)
{
drop bomb
}
would do the same for y variables.
EDIT: Beat me to it yourself
Edited by NACGames, 10 May 2009 - 11:19 PM.
#12
Posted 10 May 2009 - 11:20 PM
With help like this, I'll soon be having a demo level ready for you all to play soon!
EDIT:
These work! At least, sorta. Better than they did before. When the enemy is coming from the right and MM from the left, it does what its supposed to do, drop the bomb inches in front of MM's nose so that he walks into it.
But on the flipside, if the enemy is coming from the left and MM from the right, the enemy drops the bomb a good distance away, not sure why that is.
Edited by Darkflamewolf, 11 May 2009 - 12:25 AM.
#13
Posted 25 November 2010 - 06:04 PM
thanks, I understand now, I'm currently not on in a position to test it out now, but when I get home, I'll work through it and get back to let you all know if it worked or not. (Chances are it will, with such grand help you've all given me.) I still have one unsolved issue a few pages back (page 4) about MM contacting moving platforms that are already on a path.
Would be awesome if my noob GML questions were answered there too.
Thanks everyone! You've all been so nice!
With help like this, I'll soon be having a demo level ready for you all to play soon!
EDIT:
These work! At least, sorta. Better than they did before. When the enemy is coming from the right and MM from the left, it does what its supposed to do, drop the bomb inches in front of MM's nose so that he walks into it.
But on the flipside, if the enemy is coming from the left and MM from the right, the enemy drops the bomb a good distance away, not sure why that is.
x0 and y0 seem to sit in the center of the sprite frame. Is your megaman sprite kinda off center?
By and by, working on a megaman game myself. this topic may have helped me as well.
EDIT: Ok, yeah, getting the problem myself. If you approach it from the left, it triggers at the right distance,but if you come from the right, you have to be inside the sprite before it tries to melee. think it has something to do with the origin setting in sprites... anyone know how to fix it?
Edited by Arusiasotto, 25 November 2010 - 08:29 PM.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











