Help - Search - Members - Calendar
Full Version: Slopes
Game Maker Community > Working with Game Maker > Advanced Users Only
gamma games
I need help with the physics on this... OR... if you have a better way without using physics, that would be AWESOME.







Thanks a bunch!
Loganvz
QUOTE (gamma games @ Jun 29 2007, 08:58 PM)
I need help with the physics on this... OR... if you have a better way without using physics, that would be AWESOME.







Thanks a bunch!
*

I want to know to
IceMetalPunk
I assume you already have the "move up a slope" code, you just want to know how to vary the speed with the steepness of the slope.

In that case, check the direction from the previous (x,y) to the current (x,y), and use that number in the speed calculation.

For example, try something like this:

CODE
/* Make sure you've moved before checking the direction. */

if (x!=xprevious or y!=yprevious) {
dir=point_direction(xprevious,yprevious,x,y);
}

/* Make sure the "dir" variable is never 0, just so we don't get a divide by 0 error. */

if (dir==0) { dir=1; }

/* Set the base speed, i.e. the speed whem moving straight from left to right. */

basespeed=5;

/* Calculate the speed based on the base speed and slope steepness. */

speed=2*basespeed/dir;


Removing the comments will make it seem smaller tongue.gif . And you can choose whatever base speed you want.

-IMP wink1.gif smile.gif

*EDIT* As for "flying off" with the same speed and direction, just use this:

CODE
direction=point_direction(xprevious,yprevious,x,y);
speed=point_distance(xprevious,yprevious,x,y);


As for rotating, you can use image_angle, but since that's the same thing as the transform sprite D&D... You'll need to make the sprite face dead right in the first frame, choose Animations->Rotation->Counter-Clockwise with 36 frames, 360 degrees. Then, in the STEP event, set image_index=direction/10;
gamma games
wow, thanks. Ill tell you if i get any errors. Anyone else have any idea's?
gamma games
Sorry,
I can't seem to get the coding right.. could u post up an example?
IceMetalPunk
I wrote that off the top of my head, so there may be problems with it that I overlooked.

Please post whatever problems you are having and I'll try to revise the code.

-IMP wink1.gif smile.gif
gamma games
gives me an error... cant read the dir==0 or dir=1..
gamma games
thanks, it works
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.