Platformer slopes ?

H

hazonsassoun

Guest
Hello ! First: sorry for my bad english.
I really need your help because I searched very longtime tutorials on Youtube and internet but I did not find what I searched. So, I post here.

I want to make a platformer game with perfectly curve and smooth ground. But I want my sprite to be perpendicular to the ground (and this is very difficult for me)
Hox to do this ?

--> My character sprite is a simple cube/square 2D
--> My level (ground and blocks) is 1 sprite with precise collision shape (with the size of the room)
--> There is a screenshot of what I want exactly:

(if the image don't display click here: http://img4.hostingpics.net/pics/774747Capture.png )
--> I use GM:Studio

Thank you very very much !
 

GMWolf

aka fel666
what you want to do is aproximate the gradient of the slope under the player.
1. Find the center point where the player collided with terrain.
2. look to the left and right of it (check by a small ammount, like 2 -5 pixels)
3. find where how high the terrain is at the two points.
4. calculate the gradient (trigonometry).
5. set the angle of your player.

Hopefully this should get you started. The hardest part here is finding the height of the terrain at each point.
good luck :)

(I can give you more detail if necessary, but i will not give you code.)
 
H

hazonsassoun

Guest
Thank you for answer. Maybe because my english is bad I did not understand :/
what is the "center point where the player collided with terrain" ? my sprite is 32x32 and the origin is 16,32, / what does mean your 2. , did not understand 3.
Is it possible you explain more plz ? :)
 

Conbeef

Member
Code:
var maxcheck = 16;
if place_meeting(x,y+1,o_block){
//Find p1
for (i=0;i<=maxcheck;i+=1){
        if position_meeting(bbox_left,bbox_bottom+i,p_block){
            p1=i;
            break;
        }
}
//Find p2
for (i=0;i<=maxcheck;i+=1){
        if position_meeting(bbox_right,bbox_bottom+i,p_block){
            p2=i;
            break;
        }
}
//Now, rotate the sprite!
image_angle=point_direction(bbox_left,bbox_bottom+p1,bbox_right,bbox_bottom+p2);
}
here is a nifty piece of code I've found

EDIT: put this in a script and run this script whenever you want the image_angle to change on the slopes
 
H

hazonsassoun

Guest
I will try
It works but when the slope grows up, my character stops
 
Last edited by a moderator:
Top