Jump to content


Photo

Movement


  • Please log in to reply
6 replies to this topic

#1 darkkyoun

darkkyoun

    GMC Member

  • New Member
  • 44 posts
  • Version:GM8

Posted 01 July 2012 - 05:09 AM

Hi,
I am currently trying to make my object move from x1 to x2 smoothly. However my current code does not allow me so
The current code I am using to change the object direction are :

if going_left=3  // when in this state
        if (place_meeting(x,y,sticky_obj)) = false // check if we run out of sticky_obj
        {
            hspeed=0;
            gravity=0;
            vspeed=2;
            image_angle = 90;
        }


which lead to the scene below
Posted Image



So my question is, how to make it move smoothly [See Picture below]
Posted Image

Edited by darkkyoun, 01 July 2012 - 08:50 AM.

  • 0

#2 robinsblade

robinsblade

    GMC Member

  • GMC Member
  • 663 posts
  • Version:GM8

Posted 01 July 2012 - 03:30 PM

try using a path? that should work but i have not gotten into using paths yet so i cant help ya there ^^
  • 0

#3 PetzI

PetzI

    GMC Member

  • GMC Member
  • 1028 posts
  • Version:GM8.1

Posted 01 July 2012 - 05:47 PM

When you want the instance to start curving, give it a speed and an acceleration in the opposite direction. If you haven't used it yet, you can use Game Maker's default gravity and gravity_direction variables, otherwise you'll have to use your own and have to change the player's position in the Step event. The acceleration you give it should be equal to V^2 / R, where V is the speed you're giving it and R the radius of the (semi-)circle you want it to describe. This will cause his speed to remain constant and he'll have a circular trajectory. This may need some tweaking, but the general scheme should work.

Edited by PetzI, 01 July 2012 - 05:48 PM.

  • 0

#4 Koaske

Koaske

    GMC Member

  • GMC Member
  • 383 posts
  • Version:GM8

Posted 01 July 2012 - 06:03 PM

So what you basically want is a path that would look natural, right? Is this the only kind of situation where you want to make the path smooth, or are there other ones? In your picture, the character actually travels along the sides of a rectangle:
Posted Image

What you want the character to do is to take path that is the shape of a half-circle/half-ellipse:
Posted Image

The next part will require some math knowledge.
If you know which points belong to the rectangle (you know the equations of the lines that form its edges), you can calculate the equation of the ellipse. In other words, you know all the points that belong to the ellipse and you can just have the character to travel all these points in order. This will make the character walk in an elliptic path, which will look smooth in the situation you have in your picture.

If the turn the character will have to take is always the same (he always takes to same path from point x1 to point x2), you could try using paths too.

If this is not enough and you need to use pathfinding in more complex situations that have more obstacles and you need a different kind of smooth motion, you should probably take a look at "Motion Planning" in GM's documentation. Pathfinding isn't an easy problem to solve in game programming, and finding a good path requires a lot of calculation on the computer's part.

There is also an action called "step avoiding" under the motion tab. You might want to experiment with that too to see if it fits your needs. I once tried to do this in a project ages ago, and it didn't quite work like how I wanted it to. If I worked on a project like that before, I might consider using some pathfinding algorithm like A* and configuring it to suit my needs.

By the way, I wish all the people posting questions here would draw a picture about their problem, like you did.
  • 0

#5 darkkyoun

darkkyoun

    GMC Member

  • New Member
  • 44 posts
  • Version:GM8

Posted 06 July 2012 - 02:08 AM

So what you basically want is a path that would look natural, right? Is this the only kind of situation where you want to make the path smooth, or are there other ones? In your picture, the character actually travels along the sides of a rectangle:
Posted Image

What you want the character to do is to take path that is the shape of a half-circle/half-ellipse:
Posted Image

The next part will require some math knowledge.
If you know which points belong to the rectangle (you know the equations of the lines that form its edges), you can calculate the equation of the ellipse. In other words, you know all the points that belong to the ellipse and you can just have the character to travel all these points in order. This will make the character walk in an elliptic path, which will look smooth in the situation you have in your picture.

If the turn the character will have to take is always the same (he always takes to same path from point x1 to point x2), you could try using paths too.

If this is not enough and you need to use pathfinding in more complex situations that have more obstacles and you need a different kind of smooth motion, you should probably take a look at "Motion Planning" in GM's documentation. Pathfinding isn't an easy problem to solve in game programming, and finding a good path requires a lot of calculation on the computer's part.

There is also an action called "step avoiding" under the motion tab. You might want to experiment with that too to see if it fits your needs. I once tried to do this in a project ages ago, and it didn't quite work like how I wanted it to. If I worked on a project like that before, I might consider using some pathfinding algorithm like A* and configuring it to suit my needs.

By the way, I wish all the people posting questions here would draw a picture about their problem, like you did.



Sorry for the super late reply. But can show me an example? is there any tutorials that teaches this ? as now, I'm not being taught.
  • 0

#6 Terrified Virus

Terrified Virus

    Moderators Plaything

  • GMC Member
  • 724 posts
  • Version:GM:Studio

Posted 06 July 2012 - 05:07 AM

So what you basically want is a path that would look natural, right? Is this the only kind of situation where you want to make the path smooth, or are there other ones? In your picture, the character actually travels along the sides of a rectangle:
Posted Image

What you want the character to do is to take path that is the shape of a half-circle/half-ellipse:
Posted Image

The next part will require some math knowledge.
If you know which points belong to the rectangle (you know the equations of the lines that form its edges), you can calculate the equation of the ellipse. In other words, you know all the points that belong to the ellipse and you can just have the character to travel all these points in order. This will make the character walk in an elliptic path, which will look smooth in the situation you have in your picture.

If the turn the character will have to take is always the same (he always takes to same path from point x1 to point x2), you could try using paths too.

If this is not enough and you need to use pathfinding in more complex situations that have more obstacles and you need a different kind of smooth motion, you should probably take a look at "Motion Planning" in GM's documentation. Pathfinding isn't an easy problem to solve in game programming, and finding a good path requires a lot of calculation on the computer's part.

There is also an action called "step avoiding" under the motion tab. You might want to experiment with that too to see if it fits your needs. I once tried to do this in a project ages ago, and it didn't quite work like how I wanted it to. If I worked on a project like that before, I might consider using some pathfinding algorithm like A* and configuring it to suit my needs.

By the way, I wish all the people posting questions here would draw a picture about their problem, like you did.

I would go with this concept. There are many examples in pathfinding, just search!
  • 0

#7 Koaske

Koaske

    GMC Member

  • GMC Member
  • 383 posts
  • Version:GM8

Posted 07 July 2012 - 12:25 PM

Okay, so let's try to an example on how to turn a square path into a circular path. A similar idea is used for ellipses and rectangles, but I'll use a circle and square here to make it more simple.

Posted Image

In the picture below, the blue line is the rectangular path that you have. This goes through points ABCD. Let's say C = (0,0), B = (0,2), A = (1,2) and D = (1,0). Note that I'm not using GM's inverted coordinate system here.

In the picture, I have completed this into a rectangle BCFE by making the green line. To make a rectangle, all sides need to be of length 2, which makes E = (2,2) and F = (2,0).

Now, the diameter of the orange circle needs to be 2, since all the sides of the square are 2, which makes the radius 1. (With an ellipse, we get two values from the width and the height of rectangle.) It's also easy to see that the center point of the circle is (1,1). For rectangles and squares, the center point is given by (rectX + rectWidth/2, rectY + rectHeight/2), where rectX and rectY are the coordinates of the lower-left corner of the rectangle. In this case, we get (0 + 2/2, 0 + 2/2) = (1,1). In the inverted coordinate system, (rectX, rectY) would be the upper-left corner.

After we know the center point and the radius of the circle, it's fairly easy to make the character travel the path set by the circle. I'd prefer using polar coordinates:

In character's step event (when the circle path needs to be used):

//the angle value is the current angle from the center point to the character's location in the circle
x = centerPointX + radius*cos(angle)
y = centerPointY - radius*sin(angle)
angle += amount // amount is how fast you want the character to move, for example pi/60, pi/30 ,...

Note that since GM's coordinate system is reversed, I added a minus sign in front of sin to make it act like the sin of traditional coordinate system.

Of course, you will have to make this fit in your code to make it work, but this is the general idea. Like I said, there may be easier ways like using "step avoiding", but it all depends on your game.

If you find this method too hard to understand, then I suggest you'd try a simpler movement that is easier to make. I encourage you to try this though, because trying to make new things is what makes you develop as a programmer :)
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users