17 replies to this topic

### #1 tristiano77

tristiano77

GMC Member

• GMC Member
• 349 posts
• Version:Unknown

Posted 03 January 2008 - 11:28 PM

im working on a spring physics engine which uses motion add as a very vital part of it, but i am going to have all points calculated from a set of lists instead of using an object for each point which will be much faster (thats why my water physics is fast) but since i use motion_add as a very vital (as in nothing would happen without it) part of my springs and it changes the variables speed and direction, i cant use it as one object will be calculating everything, so i was wondering if anyone knew equivelent gml which would do the same thing as motion_add so that i could modify it to work with my setup. any help would be greatly appreciated.
• 0

### #2 xshortguy

xshortguy

GMC Member

• Global Moderators
• 4355 posts
• Version:GM:Studio

Posted 03 January 2008 - 11:39 PM

Let V be the speed increase, and let A be the direction in radians.

```hspeed += Vcos(A)
vspeed -= Vsin(A)```

EDIT: Fixed thanks to Yourself.

Edited by xshortguy, 03 January 2008 - 11:41 PM.

• 0

### #3 Yourself

Yourself

The Ultimate Pronoun

• GMC Elder
• 7352 posts
• Version:Unknown

Posted 03 January 2008 - 11:40 PM

vspeed += Vsin(A)

That should be -=, not +=.
• 0

### #4 tristiano77

tristiano77

GMC Member

• GMC Member
• 349 posts
• Version:Unknown

Posted 03 January 2008 - 11:43 PM

wow. that was quick. yay! thanks!
• 0

### #5 IceMetalPunk

IceMetalPunk

InfiniteIMPerfection

• GMC Elder
• 9603 posts
• Version:GM:Studio

Posted 03 January 2008 - 11:57 PM

vspeed += Vsin(A)

That should be -=, not +=.

<{POST_SNAPBACK}>

Only because GM (and most computer graphics systems) invert the Y-Axis. However, if you enter 3D mode, it should be changed to +=.

-IMP
• 0

Are you an artist who likes creating original creature designs? Maybe you can help out with Elementa here! Give it a look; you might like the idea

### #6 Yourself

Yourself

The Ultimate Pronoun

• GMC Elder
• 7352 posts
• Version:Unknown

Posted 04 January 2008 - 12:03 AM

However, if you enter 3D mode, it should be changed to +=.

No, motion_add() doesn't change the way it works just because you're in 3D. Additionally, there's no reason that you'd have to do that anyway. You can define directions any way you want.
• 0

### #7 IceMetalPunk

IceMetalPunk

InfiniteIMPerfection

• GMC Elder
• 9603 posts
• Version:GM:Studio

Posted 04 January 2008 - 12:08 AM

I'm pretty sure that in 3D mode, the Y-Axis is flipped to match the "normal" graphing axis. If the Y-Axis is flipped, wouldn't the vertical direction you move in need to be made its opposite?

-IMP
• 0

Are you an artist who likes creating original creature designs? Maybe you can help out with Elementa here! Give it a look; you might like the idea

### #8 Yourself

Yourself

The Ultimate Pronoun

• GMC Elder
• 7352 posts
• Version:Unknown

Posted 04 January 2008 - 12:10 AM

The only reason it "flips" is because the projection has moved to look at the x-y plane from the other side. The mathematics behind motion_add() won't suddenly change because of it. It still affects hspeed and vspeed in the same way and they still have the same meaning.
• 0

### #9 xshortguy

xshortguy

GMC Member

• Global Moderators
• 4355 posts
• Version:GM:Studio

Posted 04 January 2008 - 12:22 AM

The reason why it is '-=' instead of '+=' is because Vsin(A) moves down along the positive y-axis, and the vector with a speed and direction of A will move up on the screen, which is in the direction of the negative y-axis. This is a consequence of how angles are defined in game maker.
• 0

### #10 tristiano77

tristiano77

GMC Member

• GMC Member
• 349 posts
• Version:Unknown

Posted 25 October 2008 - 09:16 PM

Sorry that this is old, but I didn't actually get back to this project until now.
I need the input to be speed and direction in degrees
I also need the output to be the speed and direction in degrees, hspeed and vspeed aren't what I am looking for.

Plez?

and I'm not sure which one of you is right...

Edited by tristiano77, 25 October 2008 - 09:16 PM.

• 0

### #11 acrog2

acrog2

average user

• GMC Member
• 1118 posts

Posted 25 October 2008 - 11:16 PM

hspeed/vspeed can be converted to direction/speed:
direction = arctan(vspeed/hspeed)
speed = sqrt(sqr(vspeed)+sqr(hspeed))

pretty sure of the math.

-acrog2

Edited by acrog2, 25 October 2008 - 11:16 PM.

• 0

### #12 Tepi

Tepi

GMC Member

• Global Moderators
• 4248 posts
• Version:GM:Studio

Posted 26 October 2008 - 09:27 PM

You don't need to do the conversion, Game Maker does it itself. You change hspeed and vspeed - direction and speed changes, you change direction and speed - hspeed and vspeed changes. So assignments and comparisons should work very well for both coordinate systems.

That's the way it goes, folks.
• 0

### #13 bc.cho

bc.cho

GMC Member

• New Member
• 23 posts

Posted 27 October 2008 - 06:33 AM

yep. hspeed and vspeed are respectively updated to what direction and speed are.

gm also does all of the vectors for you in motion_add(...), but if you want to replicate it yourself, calculate the hor and vert bits of the new speed and direction (using trig) and do this:

```hspeed += temp_hspeed;
vspeed += temp_vspeed;```

good luck
• 0
.....

### #14 tristiano77

tristiano77

GMC Member

• GMC Member
• 349 posts
• Version:Unknown

Posted 30 October 2008 - 09:56 PM

Thanks acrog, but the next two have it wrong :\
I'm calculating hundreds of objects at once, their variables stored in lists. I need all the objects to have directional gravity in multiple directions at once. Therefore, a lot of calls will be made to the motion add equivilent function, and since it is all being calculated by one stationary object... you get it.
• 0

### #15 Tepi

Tepi

GMC Member

• Global Moderators
• 4248 posts
• Version:GM:Studio

Posted 31 October 2008 - 02:33 PM

I'm calculating hundreds of objects at once, their variables stored in lists. I need all the objects to have directional gravity in multiple directions at once. Therefore, a lot of calls will be made to the motion add equivilent function, and since it is all being calculated by one stationary object... you get it.

No I didn't get that. It is slow? That's just the most simple and probably the fastest way to do it. I see no problem in multiple simultaneous motion_add()'s. Equivalent? Read my post about conversions.

Thanks acrog, but the next two have it wrong :\

Yes, the conversion needs to be done using radtodeg(), not degtorad(). The arctan returns radians, and doesn't take angle units as input.
• 0

### #16 acrog2

acrog2

average user

• GMC Member
• 1118 posts

Posted 01 November 2008 - 02:08 AM

yeah, it should be
PRE
```direcion = radtodeg(arctan(hspeed/vspeed))
speed =sqrt(sqr(hspeed)+sqr(vspeed))```

@tepi the degtorad was for the input of sin/cos in the motion add function.

-acrog2

Edited by acrog2, 01 November 2008 - 03:13 AM.

• 0

### #17 Tepi

Tepi

GMC Member

• Global Moderators
• 4248 posts
• Version:GM:Studio

Posted 01 November 2008 - 02:32 PM

@tepi the degtorad was for the input of sin/cos in the motion add function.

sin and cos returns distance units, and motion_add() takes no input in distance units...
• 0

### #18 acrog2

acrog2

average user

• GMC Member
• 1118 posts

Posted 01 November 2008 - 02:42 PM

The degtorad was for use here:

hspeed += Vcos(A)
vspeed -= Vsin(A)

where A needs to be in radians. The original poster wanted to know how to convert degrees to radians.

I need the input to be speed and direction in degrees

-acrog2

Edited by acrog2, 01 November 2008 - 02:43 PM.

• 0