# Help me to understand about motion with variable acceleration in 2D

Page 1 of 1

## 3 Replies - 984 Views - Last Post: 23 February 2017 - 03:32 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=401560&amp;s=59d93953c18c022899d7a66549726a24&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 ryosaeba

Reputation: 0
• Posts: 4
• Joined: 20-February 17

# Help me to understand about motion with variable acceleration in 2D

Posted 20 February 2017 - 04:06 AM

Hello everyone, be patient with me because I am not much into physics and just now start to understand about vector algebra. In this days I got a lot of confusion in my head about motion in 2D space with a variable acceleration.
I was working on the idea to make a simple game about airplane in a sidescroll view 2d like Super Mario (the framework is gamemaker) but I still got confusion about the getting the X and Y position of my object.
From what I understand untill now let's say my object start with velocity 0 and I apply some thrust to it with direction 0 (mean east) at the moment not considering gravity acceleration.
I will get something like this in my main loop:

```...
speed += acc*deltatime;

x += (oldspeed + speed) * cos(degtorad(dir));
y -= (oldspeed + speed) * sin(degtorad(dir));

oldspeed = speed;
....

```

So with this code my airplane even if I not accelerate and decide to control my tail airelon change direction and make loop keeping the actual speed I am going to, that's nice. But I don't think it's currect way to doing it.
Basically dir is the direction my plane is pointing but it's wrong change it, the truth will be I am changing the angle of the tail airelon for make my plane pitch or dive and if I add the gravity force on my project offcurse it will not act as I want to (because as per example I consider my plane fly on dir = 0, gravity will be pointing at 270° but with the y * sin(degtorad(0)) will be 0 and not falling offcurse.
I am sorry I know it's stupid question but I'm really stuck so will be glad for one help on understanding.
Another addition, gamemaker not use strurcture like vectors sadly. Thank you and best regards.

Is This A Good Question/Topic? 0

## Replies To: Help me to understand about motion with variable acceleration in 2D

### #2 UG Cyber

Reputation: 36
• Posts: 611
• Joined: 24-July 08

## Re: Help me to understand about motion with variable acceleration in 2D

Posted 21 February 2017 - 06:48 PM

Im not really understanding the question.
Is your airplane moving in the correct direction before you add gravity?
If you remove the variable velocity and simply make it static, does it do what it is suppose to?

Can you show more code or provide the entire code so we can step through it and see what might be wrong?

### #3 BBeck

• Here to help.

Reputation: 792
• Posts: 1,886
• Joined: 24-April 12

## Re: Help me to understand about motion with variable acceleration in 2D

Posted 22 February 2017 - 04:50 AM

You may want to check out my Acceleration Tutorial. The actual tutorial is here. You are probably not working with XNA, and so the linked source code and project may be of limited use. You could download it and at least look at the source code.

But the tutorial should be helpful even without the source code. That's one of the few where I spent a great deal of time discussing things rather than just simply writing a code example.

In the code, I addressed much of what you are talking about except I went with the even more simple example of a ship in space. All this is in 2D despite the fact that I've mostly done 3D. I wanted to get the concepts down before attempting it in 3D.

All the basic concepts of motion should be in the tutorial. You don't have gravity or drag. But gravity is just another acceleration vector in the direction of the planet. You will fall until something stops you, such as the ground. Remove that and you will continue to fall.

Drag is more of a resistance to velocity. The way I would deal with drag is a deceleration vector that's length is determined by the volume of air displaced. Basically you take a silhouette of the object and sweep it through the space it occupies during the time period and calculate the volume of air in that swept area. This gets into displacement. But I think the weight of that volume of air determines how much force is needed to move it out of the way.

You may also want to watch my Vectors video.

### #4 ryosaeba

Reputation: 0
• Posts: 4
• Joined: 20-February 17

## Re: Help me to understand about motion with variable acceleration in 2D

Posted 23 February 2017 - 03:32 AM

BBeck, on 22 February 2017 - 04:50 AM, said:

You may want to check out my Acceleration Tutorial. The actual tutorial is here. You are probably not working with XNA, and so the linked source code and project may be of limited use. You could download it and at least look at the source code.

But the tutorial should be helpful even without the source code. That's one of the few where I spent a great deal of time discussing things rather than just simply writing a code example.

In the code, I addressed much of what you are talking about except I went with the even more simple example of a ship in space. All this is in 2D despite the fact that I've mostly done 3D. I wanted to get the concepts down before attempting it in 3D.

All the basic concepts of motion should be in the tutorial. You don't have gravity or drag. But gravity is just another acceleration vector in the direction of the planet. You will fall until something stops you, such as the ground. Remove that and you will continue to fall.

Drag is more of a resistance to velocity. The way I would deal with drag is a deceleration vector that's length is determined by the volume of air displaced. Basically you take a silhouette of the object and sweep it through the space it occupies during the time period and calculate the volume of air in that swept area. This gets into displacement. But I think the weight of that volume of air determines how much force is needed to move it out of the way.

You may also want to watch my Vectors video.

Thank yuo for the effort, I am reading the code, I had used XNA and know C# but I got difficulty mostly because on GM is not available any function like Transform Matrix, nor vectors so my problem is working only with X and Y.