# Hovercraft Movement

9 replies to this topic

### #1 Don Arthuro

Don Arthuro

ArDiGames.com

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

Posted 06 October 2007 - 11:26 AM

Im making a game where you control a hovercraft. I got this movement:
x+=lengthdir_x(speed_,direction)
y+=lengthdir_y(speed_,direction)
x+=lengthdir_x(speed_hor,direction-90)
y+=lengthdir_y(speed_hor,direction-90)

direction=point_direction(x,y,mouse_x,mouse_y)
so that is where its facing at. When speed is smaller then 0 its moving backwards
movementdir=point_direction(xprevious,yprevious,x,
y)
so thats the actually direction

now when the hover has a collision with a wall it has to bounce of, but im not sure how to do this

So when it has a colllision the facingdirection will stay the same, but the speed and horizontalspeed has to change.
Here is an image to show what I mean, I hope you'll understand it

• 0

### #2 oO[VreXoR]Oo

oO[VreXoR]Oo

GMC Member

• New Member
• 70 posts

Posted 06 October 2007 - 11:39 AM

what about the bounce against objects action?
• 0

### #3 Don Arthuro

Don Arthuro

ArDiGames.com

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

Posted 07 October 2007 - 12:03 PM

thats not possible in this case.
• 0

### #4 Rtyp06

Rtyp06

GMC Member

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

Posted 07 October 2007 - 01:47 PM

From GM help under real valued functions:

"lengthdir_x(len,dir) Returns the horizontal x-component of the vector determined by the indicated length and direction.

Can anyone explain wtf this means since I see everyone using it? I know what a vector is but...

Anyway, I'm able to get hovercraft type movements by making two variables, x_axis and y_axis and changing these between negative and positive values from the players input. Then I simply add these values to the x and y values of the object in it's step event. Then I use the bounce against solid objects to get the rebounding effect.
• 0

### #5 Flamer_Shaftglutton

Flamer_Shaftglutton

GMC Member

• GMC Member
• 304 posts

Posted 07 October 2007 - 03:02 PM

From GM help under real valued functions:

"lengthdir_x(len,dir) Returns the horizontal x-component of the vector determined by the indicated length and direction.

Can anyone explain wtf this means since I see everyone using it? I know what a vector is but...

Anyway, I'm able to get hovercraft type movements by making two variables, x_axis and y_axis and changing these between negative and positive values from the players input. Then I simply add these values to the x and y values of the object in it's step event. Then I use the bounce against solid objects to get the rebounding effect.

<{POST_SNAPBACK}>

lengthdir_x() is the x_axis of a triangle you make when you go (len) distance in (dir) direction.
lengthdir_y() is the y_axis of the triangle.

Generally I use it by: lengthdir_x(point_distance(x,y,x2,y2),point_direct
ion(x,y,x2,y2) to give me the x_axis of the triangle between the object and another point.
• 0

### #6 Rtyp06

Rtyp06

GMC Member

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

Posted 07 October 2007 - 03:29 PM

lengthdir_x() is the x_axis of a triangle you make when you go (len) distance in (dir) direction.
lengthdir_y() is the y_axis of the triangle.

Generally I use it by: lengthdir_x(point_distance(x,y,x2,y2),point_direct
ion(x,y,x2,y2) to give me the x_axis of the triangle between the object and another point.

<{POST_SNAPBACK}>

Ok I know that any 3 points make a triangle. And the three sides are usually represented by hypotenuse, opposite and adjacent.

I also know that lengthdir_x and lengthdir_y are functions that you pass two arguments length and direction. I just don't quite understand what useable value these functions are returning.

I see that it's the length in the x direction (axis) and y direction respectively, (hence "lengthdir") but what good are these values? I'm not really seeing reasons to need these values and how they would apply to movement of an object...
• 0

### #7 jabelar

jabelar

GMC Member

• New Member
• 2980 posts

Posted 07 October 2007 - 04:51 PM

I would actually try a different approach. I would have a variable for the rotation (the object would be rotated this amount) of the hovercraft that is separate from the movement direction. When the player does something like accelerate you'd do that relative to the rotation of the object, but for bouncing you'd do the bounces relative to the movement of the object.

Not sure if that helps, but I think the math gets complicated if you combine the movement and rotation ...
• 0

### #8 Don Arthuro

Don Arthuro

ArDiGames.com

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

Posted 07 October 2007 - 09:09 PM

can anybody give me the code of the bounce against objects action?
then I can change it to use it
• 0

### #9 jabelar

jabelar

GMC Member

• New Member
• 2980 posts

Posted 07 October 2007 - 10:18 PM

can anybody give me the code of the bounce against objects action?
then I can change it to use it

<{POST_SNAPBACK}>

If you look at the pinned topics at the top of the Novice forum, you see there is a document "D&d actions and their GML equivalents" that can help you with understanding what the drag&drop actions in Gamemaker are really doing.

It says that the bounce against objects action is equivalent to:

or 1).
1).

Of course that doesn't really help if you want to modify it. If you want precision bouncing then you probably have to scan both sprites bit by bit and figure out what should happen ...
If you're bouncing off of known angle surfaces, then it might be simpler ...
• 0

### #10 Don Arthuro

Don Arthuro

ArDiGames.com

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

Posted 08 October 2007 - 09:14 AM

i need to modify it so those actions dont help
the walls have simple angles (0,45,90,135,180,225,270 and 315)
so thats not the problem
I need to calculate the direction it bounds to and then calculate the new horizontal and vertical speed
• 0

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users