OctoMoosePrime
Member
Hello everyone.
I'm trying to make a local multiplayer platformer but can't get the basic collisions to work properly.
I started by using the classic hsp/vsp movement/collision code from Shaun Spaldings platformer tutorials but I had problems implementing collisions with other players.
(standing on, side-pushing, jumping with other player on top etc.)
So I decided to instead try using Game Makers built in physics functions because that seemed like a logical approach.
I found "Rm2kdev's physics platformer" youtube tutorial, and it solved the player to player functions without any additional code. So it feels like a better choice for the game.
But here comes the problem he kept a bug where the wall is detected as ground, reseting the jump, making you able to climb walls, as a "feature".
(And since obj_Player uses obj_Wall as parent, you're also able to chestbump other players all the way to space)
Noone in the youtube comment section had an answer and the very few other "physics platformer" examples I found had the same issue.
It's just using the built in physics collisions by putting an empty comment in a collision with obj_wall event, so i added a "if place_meeting(x,y+1,obj_wall)" to enable a jump, but it's detected when you collide on the x-axis aswell, even if you're not colliding on the y-axis.
I thought i could cheat it by creating an object following obj_players feet and enable jumping when that object collide with obj_wall, but the tracking didn't follow the movements correctly, so not even that worked.
How do i get "if place_meeting(x,y+1,obj_wall)" to only react on the x-axis, as it's supposed to?
Does the built in collision somehow override the code, and if so how do i work around that?
Obj_players code
-Creation
-Step
-Collision with obj_wall
obj_wall is parent to obj_player. Both objects uses physics
Physics properties for obj_wall: 0s on everything. Solid
Physics properties for obj_player: Density: 1, Linear Damping: 1, 0s on everything else.
Physics properties for room0: Gravity y: 70.0
I'm trying to make a local multiplayer platformer but can't get the basic collisions to work properly.
I started by using the classic hsp/vsp movement/collision code from Shaun Spaldings platformer tutorials but I had problems implementing collisions with other players.
(standing on, side-pushing, jumping with other player on top etc.)
So I decided to instead try using Game Makers built in physics functions because that seemed like a logical approach.
I found "Rm2kdev's physics platformer" youtube tutorial, and it solved the player to player functions without any additional code. So it feels like a better choice for the game.
But here comes the problem he kept a bug where the wall is detected as ground, reseting the jump, making you able to climb walls, as a "feature".
(And since obj_Player uses obj_Wall as parent, you're also able to chestbump other players all the way to space)
Noone in the youtube comment section had an answer and the very few other "physics platformer" examples I found had the same issue.
It's just using the built in physics collisions by putting an empty comment in a collision with obj_wall event, so i added a "if place_meeting(x,y+1,obj_wall)" to enable a jump, but it's detected when you collide on the x-axis aswell, even if you're not colliding on the y-axis.
I thought i could cheat it by creating an object following obj_players feet and enable jumping when that object collide with obj_wall, but the tracking didn't follow the movements correctly, so not even that worked.
How do i get "if place_meeting(x,y+1,obj_wall)" to only react on the x-axis, as it's supposed to?
Does the built in collision somehow override the code, and if so how do i work around that?
Obj_players code
-Creation
Code:
phy_fixed_rotation = true;
move_speed = 200;
max_xspeed = 4;
jump_force = -100;
jumptimer = 0;
dir = 1;
Code:
///Movement and collision
key_right = keyboard_check(vk_right);
key_left = keyboard_check(vk_left);
key_jump = keyboard_check_pressed(vk_up);
key_jump_held = keyboard_check(vk_up);
if key_left{
physics_apply_force(x,y,-move_speed,0);
dir = -1;
}else if key_right{
physics_apply_force(x,y,move_speed,0);
dir = 1;
}else{
phy_speed_x = (phy_speed_x/8 * 7); //decelleration
}
if key_jump{ //jump
if jumptimer >0{
physics_apply_impulse(x,y,0,jump_force);
}
}
//speed < maxspeed
phy_speed_x = max(min(phy_speed_x,max_xspeed),-max_xspeed);
//varialbe Jump height
if (phy_speed_y <0) && (!key_jump_held) && !place_meeting(x,y,obj_player){
phy_speed_y = max(phy_speed_y, (phy_speed_y /6 *5));
}
if jumptimer > 0 { //"coyote" jump-timer
jumptimer -= 1;
}
//Attempt at fixing Collision (kind of works, but you cant jump if you're standing next to a wall/player)
if (place_meeting(x,y+1,obj_wall) && !place_meeting(x+1,y,obj_wall)){
jumptimer = 5;
}
Code:
//comment needed to initiate physics collision
Physics properties for obj_wall: 0s on everything. Solid
Physics properties for obj_player: Density: 1, Linear Damping: 1, 0s on everything else.
Physics properties for room0: Gravity y: 70.0