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: [Request / Listing] Vertex Move to Point (GML)  (Read 3003 times)

0 Members and 1 Guest are viewing this topic.
[Request / Listing] Vertex Move to Point (GML)
« on: June 12, 2006, 08:35:19 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 252
What I want is a vertex moving from a starting position moving at a given position with the indicated speed.
« Last Edit: March 18, 2012, 06:26:15 am by Niek »
Logged
The Legend of Zelda: The Spell Caster
Release Date: ?

I'm a faithful man! Don't be a whimp, fight for life.
Re: Move to Point (GML)
« Reply #1 on: June 12, 2006, 08:52:04 pm »
  • ZFGC Founder
  • *
  • Reputation: +2/-0
  • Offline Offline
  • Gender: Male
  • Posts: 470
Are you talking about the delphi code that Mark Overmars used to create the function?
Logged
Re: Move to Point (GML)
« Reply #2 on: June 12, 2006, 09:21:13 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629
Well i don't know how GM does it but i figure it would probably look something like...

Code: [Select]
if (obj.x > x) obj.x-=speed;
if (obj.x < x) obj.x+=speed;
if (obj.y > y) obj.y-=speed;
if (obj.y < y) obj.y+=speed;
Logged

Ben

Re: Move to Point (GML)
« Reply #3 on: June 12, 2006, 09:23:38 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 437
Erm Helios, you suck, lol.
It'll look nothing like that, because that allows for only diagonal movement.
What it'll actually do is take the sine and cosine of the direction, multiply them by speed and then add them on to x and y respectively.
Logged
Want a place to upload your sprites and games for FREE? Look no further than GameDevotion
Re: Move to Point (GML)
« Reply #4 on: June 12, 2006, 09:26:05 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629
Erm Helios, you suck, lol.
It'll look nothing like that, because that allows for only diagonal movement.
What it'll actually do is take the sine and cosine of the direction, multiply them by speed and then add them on to x and y respectively.

Yeh I know, I didn't wish to make it complex for Master J, besides, that works pretty well if your only after simplistic movement :P, i don't actuall use functions like that if thats what you mean :P.
Logged

Ben

Re: Move to Point (GML)
« Reply #5 on: June 12, 2006, 09:27:34 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 437
Lol, fine, but he asked for it, and so he shall recieve.
Logged
Want a place to upload your sprites and games for FREE? Look no further than GameDevotion

Goodnight

Once and future Captain
Re: Move to Point (GML)
« Reply #6 on: June 13, 2006, 06:25:14 pm »
  • With a Capital G
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 706
From what I gather it's two steps...

move_towards_point(new_x, new_y, new_speed) does these calculations:

speed = new_speed
direction = arctan2(y-new_y, new_x-x) * 180 / pi
(^^ which is the same as: direction = point_direction(x, y, new_x, new_y) )

Then whenever speed and/or direction is changed, vspeed and hspeed are changed as well:

hspeed = speed * cos(direction * pi / 180)
vspeed = speed * -sin(direction * pi / 180)  <--- note the negative sine

BUT, it could be the other way around; the function actually changes hspeed and vspeed, which in turn change speed and direction. Doesn't really matter though, it's the same both ways. :P

Then it's just what Ben said, in between Step and End Step it adds those two values to x and y.
Logged
Re: Move to Point (GML)
« Reply #7 on: June 13, 2006, 06:30:27 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 252
I meant to say to create the source as a script, however, I am not going to use this for the game play, more like a vertex moving towards a point.
Logged
The Legend of Zelda: The Spell Caster
Release Date: ?

I'm a faithful man! Don't be a whimp, fight for life.

Goodnight

Once and future Captain
Re: Move to Point (GML)
« Reply #8 on: June 13, 2006, 06:41:29 pm »
  • With a Capital G
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 706
If you wanted a GML script then it would be:
Code: [Select]
speed = argument2
direction = arctan2(y-argument1, argument0-x) * 180 / pi

Which is pointless because the function already exists. :D  Unless you're asking for something different, like making it stop at that point, or applying the movement to some variables other than x and y?
Logged
Re: Move to Point (GML)
« Reply #9 on: June 13, 2006, 06:55:43 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 252
Well since you got the formula, how would it be for a vertex as a script?

Example: scr_draw_vertex_point(x_start, y_start, x_destination, y_destination, speed);
Draws a vertex from position (x_start, y_start) moving towards point (x_destination, y_destination) at the indicated speed.
« Last Edit: June 13, 2006, 07:03:21 pm by Master J »
Logged
The Legend of Zelda: The Spell Caster
Release Date: ?

I'm a faithful man! Don't be a whimp, fight for life.
Re: Vertex Move to Point (GML)
« Reply #10 on: June 15, 2006, 08:30:42 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 252
Someone...
Logged
The Legend of Zelda: The Spell Caster
Release Date: ?

I'm a faithful man! Don't be a whimp, fight for life.

mit

Re: Vertex Move to Point (GML)
« Reply #11 on: June 15, 2006, 10:14:39 pm »
  • QBASIC programmer since age 4. Take that, world.
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 1079
I'm not quite sure what you want. All I can say is that you can work out the position relative to you from a distance and direction using the built in functions instead of the trig, lengthdir_x() and lengthdir_y() they're called. So each step
Code: [Select]
x+=lengthdir_x(speed, direction)
y+=lengthdir_y(speed, direction)
is performed.

I suppose what you want could be achived with point_direction() and that?
Logged
Programmer / Spriter / Level designer / Game Director / Web Designer / Music Sequencer for
Random Highscore table:

Play the Kousou Arcade today!
  • Kousou Games
Re: Vertex Move to Point (GML)
« Reply #12 on: June 16, 2006, 01:47:34 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1635
I'm not quite sure what you mean, but you could just draw a line from xstart and ystart to xdestination and ydestination. You'd create an object which moves to that point, and then you can draw a line from the start to the object's coordinates, and move the object at a certain speed, giving the impression you're drawing a moving vertex. Or, you could just use drawing primitives which might make it easier.
Logged
Re: Vertex Move to Point (GML)
« Reply #13 on: June 16, 2006, 07:06:32 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 252
I'm not quite sure what you mean, but you could just draw a line from xstart and ystart to xdestination and ydestination. You'd create an object which moves to that point, and then you can draw a line from the start to the object's coordinates, and move the object at a certain speed, giving the impression you're drawing a moving vertex. Or, you could just use drawing primitives which might make it easier.

Scooternew, you are way of the topic, re-read every post carefully and once more.

Mit, you maybe close but what I want is something like you draw a point not a line Scooternew, or not an object either, from point x_start and y_start moving to x_destination and y_destination, but instead I want a vertex.
Logged
The Legend of Zelda: The Spell Caster
Release Date: ?

I'm a faithful man! Don't be a whimp, fight for life.
Re: Vertex Move to Point (GML)
« Reply #14 on: June 17, 2006, 02:07:51 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 2245
I'm not quite sure what you mean, but you could just draw a line from xstart and ystart to xdestination and ydestination. You'd create an object which moves to that point, and then you can draw a line from the start to the object's coordinates, and move the object at a certain speed, giving the impression you're drawing a moving vertex. Or, you could just use drawing primitives which might make it easier.

Scooternew, you are way of the topic, re-read every post carefully and once more.

Mit, you maybe close but what I want is something like you draw a point not a line Scooternew, or not an object either, from point x_start and y_start moving to x_destination and y_destination, but instead I want a vertex.
you can't go blame scooternew for interpreting it wrong
it's your question that's the problem, notice how the following responses basically start with "I don't know what you want"? nobody understands specifically what the hell you want to do

Logged

mit

Re: Vertex Move to Point (GML)
« Reply #15 on: June 17, 2006, 08:57:39 pm »
  • QBASIC programmer since age 4. Take that, world.
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 1079
I'm just not sure what you mean by vertex, but if you want a point that moves from one place to another, that isn't an object, then I guess you could do something like:
Code: [Select]
p+= (p < point_distance(startX, startY, endX, endY) )
d=point_direction(startX, startY, endX, endY)
draw_point( startX + lengthdir_x(p, d) , startY + lengthdir_y(p, d) )
in the draw event of a controlling object (define p=0 first).
Logged
Programmer / Spriter / Level designer / Game Director / Web Designer / Music Sequencer for
Random Highscore table:

Play the Kousou Arcade today!
  • Kousou Games
Re: Vertex Move to Point (GML)
« Reply #16 on: June 19, 2006, 07:43:41 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 252
What about speed?
Logged
The Legend of Zelda: The Spell Caster
Release Date: ?

I'm a faithful man! Don't be a whimp, fight for life.

mit

Re: Vertex Move to Point (GML)
« Reply #17 on: June 19, 2006, 09:51:57 pm »
  • QBASIC programmer since age 4. Take that, world.
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 1079
Uh, speed would just be the amount you increase p by, so repeat the adding of it:
Code: [Select]
repeat 5 p+= (p < point_distance(startX, startY, endX, endY) )
d=point_direction(startX, startY, endX, endY)
draw_point( startX + lengthdir_x(p, d) , startY + lengthdir_y(p, d) )
Logged
Programmer / Spriter / Level designer / Game Director / Web Designer / Music Sequencer for
Random Highscore table:

Play the Kousou Arcade today!
  • Kousou Games
Re: Vertex Move to Point (GML)
« Reply #18 on: June 20, 2006, 08:18:49 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1635
Quote
What I want is a vertex moving from a starting position moving at a given position with the indicated speed.
I'm still confused. A moving vertex? Moving at a position?

This just looks like move_towards_point.
Logged
Pages: [1]   Go Up

 


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



Page created in 0.197 seconds with 73 queries.