planet platformer issues

G

geekdude

Guest
So I am attempting to adapt the platformer code from heartbeasts perfect platformer tutorial:
to a situation where you walk around a planet. Gravity is now always toward the middle of the planet instead of down. moving left-right is a matter of which angle from the center of the planet you are at and up or down is accomplished by changing the radius. It seems that the while loops that are suspposed to take the character to the edge of a platform are sometimes not working at all. the horizontal collision code does not seem to work at all. Right now im getting trapped in the floor and have to jump to move. Does my code just need a complete redesign?

I can upload the gmx file if you need it. I dont have much else going on with it just yet and all graphics are placeholders.
using gamemaker 1.4.1772

Code:
//step code for main character.

circle_scr();

controls_scr();
 
planet_physics_scr();

//camera rotates to follow charicter around planet.
view_angle[0]=-aIngle+90;
_________________________________________________________
///Planet_physics

global.planet_down = point_direction(x,y,planet_obj.x,planet_obj.y);    //planet down is defined as the  direction between your x and y location and the x and y location of the center of the planet.

//check for ground
if (place_meeting (x+lengthdir_x(1, global.planet_down),y+lengthdir_y(1, global.planet_down),solid_obj)){         //if these 2 places meet: your x and y cordinates, and a point one pixel towards the middle of the planet
    vspd=0;
 
    //jump
    if (keyboard_check(vk_space)){
   // radius += jmp;
    vspd = -jmp;
    }
}

else {          //gravity
    if (vspd < 10){
         vspd += planet_obj.grav;}
    }
 
    //move horazontaly
var loop_limit2 = hspd;
if (place_meeting (x+lengthdir_x(hspd, global.planet_down-90)  , y+lengthdir_y(hspd, global.planet_down-90) , solid_obj)){
        while (!place_meeting(
                x+lengthdir_x(sign(hspd) , global.planet_down-90),
                y+lengthdir_y(sign(hspd), global.planet_down-90) , solid_obj)
            )
            {
        aIngle += sign(hspd);
        if (loop_limit2 <= 0){break;}
        loop_limit2 --;
}
hspd=0;
}
 
//move
 
aIngle += hspd;
 
//move verticaly
var loop_limit = vspd;
if (place_meeting (x+lengthdir_x(vspd, global.planet_down)  , y+lengthdir_y(vspd, global.planet_down) , solid_obj)){
        while !place_meeting(x+lengthdir_x(1 , global.planet_down),y+lengthdir_y(1, global.planet_down) , solid_obj)
            {
        radius -= (sign(vspd));
      // move_towards_point(planet_obj.x ,planet_obj.y ,sign(vspd))
       if (loop_limit <= 0){break;}
       loop_limit --;
}
vspd=0;
}
 
//move verticaly. (via gravity or jump force)
radius -= vspd;

___________________________________________________________________

///controls

var rkey = keyboard_check(ord('A'));
var lkey = keyboard_check(ord('D'));


if (rkey){
    hspd = spd;
    image_index= 12;
     }
 
if (lkey){
    hspd = -spd;
    image_index= 13;
      }
 
if (keyboard_check(ord('W'))){
    image_index= 11;
}
 
if (keyboard_check(ord('S'))){
    image_index= 10;
}

if ((!rkey && !lkey) || (rkey && lkey)){
hspd=0;
}

________________________________________________________

///circle
//go in a circle arround the planet surface

aIngle = aIngle mod 360;            //mispelling of angle insures I am not using a reserved variable.
if aIngle < 0 {aIngle += 360}

x =  planet_obj.x +  lengthdir_x(radius, aIngle);
y =  planet_obj.y +  lengthdir_y(radius, aIngle);
 
Last edited by a moderator:
I actually just tried to implement something like this in my own engine and it's a lot more difficult than it looks.
Turns out planet gravity often isn't directed towards the middle of the planet at all. In games like Super Mario Galaxy and Sonic Lost World, the point of gravity is actually the closest point to the player on the planet's surface, and that in itself is a whole can of worms.
This person has the closest solution I've seen, if it helps. They use paths to simulate the surface of a planet, and find the closest point on the path to attract the player towards.
Good luck, you're going to need it but it's thankfully not impossible.
 
G

geekdude

Guest
I'm not going to need that much complexity in the available shapes mostly just spherical planets with some platforms maybe a crater or two. and I am not planning on implementing the ability to jump from planet to planet. The plan is there will be a rocketship that takes you to space which is another room and you can get to other planets from there. All of which are other rooms. I may actually ditch the platform idea entirely as it is not central to my planned gameplay but it would be nice to have a platform element in there from time to time so that you can access a secret area.
 
G

geekdude

Guest
Im making progress. decided to actualy try the code as it is presented in the video to see how it works a bit and compare. Found out in the loops for horizontal and vertical movement the source code I was working off of was changing the actual position of the character each step mine just changed a variable that the circle script used to change the position later on. I took the call to this script and called it every time the x or y position is changed in the source code. This works better. I can walk farther but i still get stuck in the ground eventually and have to jump to go forward. also I get stuck to walls sometimes
 
Top