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: Short Coordinate Question  (Read 1145 times)

0 Members and 1 Guest are viewing this topic.
Short Coordinate Question
« on: January 31, 2013, 02:29:08 am »
  • *
  • Reputation: +2/-0
  • Offline Offline
  • Gender: Male
  • Posts: 269
Hello, ill make this short because this whole idea is decently short. so my characters mask is very small, and i am using something like if Link.x = x then blahblah. the whole code is in the spoiler and you can see it there. my question is: is there a way to make something like if link.x is = with a tolerance or giveway of like 3 or something. my code also uses > and < so it gets confuzing as you can see i tried something there to replicate my idea. if anyone has a way to go about this, help would be appreciated.

CODE:
Show content
///////////////DIRECTION(LEFTANDRIGHT)
///////////////
if Link.y = y and (Link.x+3 < x+3 or Link.x-3 < x-3)
{
alarm[1] = true
sprung = true
}

if Link.y = y and (Link.x+3 > x+3 or Link.x-3 > x-3)
{
alarm[4] = true
sprung = true
}
///////////////OTHER DIRECTION(UPANDDOWN)
///////////////
if Link.x = x and Link.y < y
{
alarm[7] = true
sprung = true
}

if Link.x = x and Link.y > y
{
alarm[10] = true
sprung = true
}
Logged

Starforsaken101

Wake the Beast
Re: Short Coordinate Question
« Reply #1 on: January 31, 2013, 02:48:38 am »
  • www.mouffers.com
  • *
  • Reputation: +69/-0
  • Offline Offline
  • Gender: Female
  • Posts: 2575
Alright, I'm not really sure I understand what you mean by tolerance, so I'm assuming it's some sort of area/circle with a radius around Link. I think the best idea here is to actually draw out a situation with graph paper. Comparing Link.x + 3 with x + 3 is the same as comparing Link.x with x: you're displacing both by the same constant. So this is kinda wonky, for sure.
Logged
  • Starforsaken101's DeviantART
Re: Short Coordinate Question
« Reply #2 on: January 31, 2013, 02:52:55 am »
  • Yeah, I don't even...
  • *
  • Reputation: +11/-4
  • Offline Offline
  • Gender: Female
  • Posts: 1008
Whity, what are you trying to do with it? That may help us help you, also what mefium is this being used in?

Edit: Read through it again, It may be coded in GML.
« Last Edit: January 31, 2013, 02:57:55 am by Kami »
Logged
Re: Short Coordinate Question
« Reply #3 on: January 31, 2013, 02:59:12 am »
  • *
  • Reputation: +2/-0
  • Offline Offline
  • Gender: Male
  • Posts: 269
What i am trying to do, its for an enemy, or obstacle. the blade things, the ones that spring out at you when you are on the same plane as them. so at the start i did the Link.x stuff, but realized that was too precise, and i wanted to sort of have a well its close to the same X so that still counts kind of thing. so its not exact. and what i meant by tolerance(sorry ive been taking an engineering class, and the vocab quiz is annoyingly engraved in my head.) tolerance is how off you can build a peice with it still being right.. so say a + or - .5 so thats what im trying to do. link.X give or take a certain number
Logged
Re: Short Coordinate Question
« Reply #4 on: January 31, 2013, 03:03:39 am »
  • Yeah, I don't even...
  • *
  • Reputation: +11/-4
  • Offline Offline
  • Gender: Female
  • Posts: 1008
I'm taking a guess those alarms set it's movement direction. I could whip something up. Are you trying to get people's opinions on it, or is it not working how you intended it to?

@Star, Gamemaker is kinda weird like that, when you have x or y by itself in a code it refers to the object that's executing codes' x or y.
Logged

Starforsaken101

Wake the Beast
Re: Short Coordinate Question
« Reply #5 on: January 31, 2013, 03:06:31 am »
  • www.mouffers.com
  • *
  • Reputation: +69/-0
  • Offline Offline
  • Gender: Female
  • Posts: 2575
That's still incredibly vague, but I think I see what you're trying to do: you're trying to put a detection circle or rectangle around obstacles/enemies that spring out at Link.

Well, the way you're doing it is pretty goofy. I would suggest you look up some very simple detection formulas. I think you'll want point in circle detection, actually. Your radius in your example would be 3.

http://stackoverflow.com/questions/481144/equation-for-testing-if-a-point-is-inside-a-circle

Here's a good link explaining the math behind it. It's pretty simple.

@Kami, hmmm...I was more talking about the math behind it, rather than the code. The algorithm Whitay wrote is really just...not...conventional? I don't know, it's just weird, which is why he's asking for help ;)
Logged
  • Starforsaken101's DeviantART
Re: Short Coordinate Question
« Reply #6 on: January 31, 2013, 03:07:02 am »
  • Doesn't afraid of anything.
  • *
  • Reputation: +42/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6964
Alright, I'm not really sure I understand what you mean by tolerance, so I'm assuming it's some sort of area/circle with a radius around Link. I think the best idea here is to actually draw out a situation with graph paper. Comparing Link.x + 3 with x + 3 is the same as comparing Link.x with x: you're displacing both by the same constant. So this is kinda wonky, for sure.

Basically this.  What you really want to compare is Link.x to x + 3 and x - 3.  You want to know when Link's x is:

-3 < x < 3

i.e. inbetween the range of -3 to 3 with respect to your object.

There are better ways of doing this, but this is crude and simple enough for now.  Do some Googling on how to detect a point's distance to a circle (by using its center and radius.  HINT: Pythagorean Theorem.)

Quote
when you have x or y by itself in a code it refers to the object that's executing codes' x or y.

Yes, it refers to the object's local instance.
Logged



i love big weenies and i cannot lie

Starforsaken101

Wake the Beast
Re: Short Coordinate Question
« Reply #7 on: January 31, 2013, 03:07:49 am »
  • www.mouffers.com
  • *
  • Reputation: +69/-0
  • Offline Offline
  • Gender: Female
  • Posts: 2575
Alright, I'm not really sure I understand what you mean by tolerance, so I'm assuming it's some sort of area/circle with a radius around Link. I think the best idea here is to actually draw out a situation with graph paper. Comparing Link.x + 3 with x + 3 is the same as comparing Link.x with x: you're displacing both by the same constant. So this is kinda wonky, for sure.

Basically this.  What you really want to compare is Link.x to x + 3 and x - 3.  You want to know when Link's x is:

-3 < x < 3

i.e. inbetween the range of -3 to 3.

Quote
when you have x or y by itself in a code it refers to the object that's executing codes' x or y.

Yes, it refers to the object's local instance.

Yeah, that could work too.
Logged
  • Starforsaken101's DeviantART
Re: Short Coordinate Question
« Reply #8 on: January 31, 2013, 04:09:39 am »
  • *
  • Reputation: +2/-0
  • Offline Offline
  • Gender: Male
  • Posts: 269
wow, got lots of help very fast. thanks to all of you. well im not a coding master, and so some of the ways are pretty goofy to be honest.. but as of now its mostly for educational. so which way would be better? doing a detection circle or just doing the -3 < x < 3? i think detection circle could be better for mine, and so i will probably go with that one, although i would be completly in the dark on how to use that in the coding without changing all of the coding.
Logged

Starforsaken101

Wake the Beast
Re: Short Coordinate Question
« Reply #9 on: January 31, 2013, 11:32:56 am »
  • www.mouffers.com
  • *
  • Reputation: +69/-0
  • Offline Offline
  • Gender: Female
  • Posts: 2575
Well, for the detection circle and Steve's way, it's all a matter of a simple if-statement. Basically all you'd have to do is change your if-statements to something more proper. You'll get used to this sort of thing the more you do gameplay programming ;)
Logged
  • Starforsaken101's DeviantART
Re: Short Coordinate Question
« Reply #10 on: January 31, 2013, 12:51:30 pm »
  • *
  • Reputation: +2/-0
  • Offline Offline
  • Gender: Male
  • Posts: 269
Okay, im going to try that out in some coding today. Thank you all for helping!
Logged
Pages: [1]   Go Up

 


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



Page created in 0.068 seconds with 42 queries.

anything