GML Basic code to arc an object from point 1 to point 2

R

Rydon_Star

Guest
Hey everyone
I have been looking around for code to just have an object move in an arc between two points. I know there are a lot of forum post out there on this topic but a lot of them are using gravity, etc. which I don't really need. I just need to be able to have an object move from point a to point b in an arc.
I finally found this code to handle that:

speed=0.1;
xx+=speed;
x = max_distance*xx;
if xx >= pi {xx = pi};
yy = sin(xx);
y = max_height*yy;

and I created an object to do this:
CREATE:
///Properties
_speed = .1;
xx = 0;
_distance = 0;
_height = 0;
yy = 32;
_entity = 0;
_endPoint = 0;

STEP:
xx += _speed;
_entity.x = _distance * xx;
yy = sin(xx);
_entity.y = -_height * yy;

if(_entity.x >= pi)
{
_entity.x = pi;
instance_destroy();
}

When I create this object I just assign the object I want to arc and the distance. And this works when I leave all the other variables the same, meaning it starts from 0,0 position. It works great, but when I try to add something like this to take into account the current objects x and y:

xx += _speed;
_entity.x += _distance * xx;
yy = sin(xx);
_entity.y += -_height * yy;

Notice the += for the entity x and y, then my object goes through the roof faster than poochie heading back to his home planet.

I know I have things like the _entity.x >= pi being an issue as it will never be destroyed, but I am not sure how to apply this to an object, regardless of where they are in a room, and have them move 16 pixels to the right in an arc.

I appreciate any help you guys can give me on this.

thanks
 
R

Rydon_Star

Guest
OK, so after some sleep and coming back to this I have figured it out. My main issue was that I was adding my entity x and y to the current x and y and not the starting x and y. I also tweaked the xx and distance so that it would calculate based upon pixels. I mainly did this with charting it out in Excel and then bringing that over to Gamemaker. If anyone needs a basic arc to point code then this should satisfy what you need. Remember that I am using this for an RPG, so I just need an entity or person to arc to a certain place across an x axis. It does not take into account anything change the y axis:

CREATE:
///Properties
_speed = .1;
xx = 0;
_distance = 0;
_height = 0;
yy = 0;
_entity = 0;
_startX = 0;
_startY = 0;

STEP:
xx += _speed;
_entity.x = _startX + (_distance * xx)/3.2;
yy = sin(xx);
_entity.y = _startY + (-_height * yy);

if(_entity.x >= (_startX + _distance))
{
_entity.x = _startX + _distance;
_entity.y = _startY;
instance_destroy();
}

Just assign the _entity to your object, and also pick your height and distance and it will arc to that point along the X-axis
 
You need a start_x/y variable
Code:
xx += _speed;
_entity.x += start_x - _distance * xx;
yy = sin(xx);
_entity.y += start_y -_height * yy;

I would use hspeed/vspeed, just an advice
 
Top