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
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: