Windows Switching characters and wall collisions

11oyd

Member
Hi! I'm relatively new to GameMaker so please forgive the rookie question.

I'm working on a platform game where I want to be able to switch between characters.
I'm currently doing this with this code inside a key pressed event:

instance_create_layer(x, y,0, obj_Angry);

instance_destroy();

The problem is that when I transform next to a wall my sprite gets stuck. I believe this is due to the collision mask being larger than the previous sprite but I need it to be bigger for the functionality of other parts of the game.
Any help much appreciated!
 

poliver

Member
1. check for the wall before transforming. if you're too close to the wall don't let transformation to happen.

2. check for the wall and create your new instance just at a slightly different position, spite mask size difference away from a wall.
 

11oyd

Member
Step event is like this:


/// Platform Physics

var rkey = keyboard_check(vk_right);
var lkey = keyboard_check(vk_left);
var jkey = keyboard_check(vk_up);

// Check for ground
if (place_meeting(x, y+1, obj_solid)) {
vspd = 0;

//jumping
if (jkey) {
vspd = -jspd;
}
} else {
// Gravity
if (vspd <10) {
vspd += grav;
}
}

// Moving Right
if (rkey) {
hspd = spd;
}

// Moving Left
if (lkey) {
hspd = -spd;
}

// Check for not moving
if ((!rkey && !lkey) || (rkey && lkey)) {
hspd = 0;
}

// Collision prevnetion


// Horizontal collisions
if (place_meeting(x+hspd, y, obj_solid)) {
while (!place_meeting(x+sign(hspd), y, obj_solid)) {
x += sign(hspd);

}
hspd = 0;
}

// Move horizontally
x += hspd;

// Vertical collisions
if (place_meeting(x, y+vspd, obj_solid)) {
while (!place_meeting(x, y+sign(vspd), obj_solid)) {
y += sign(vspd);

}
vspd = 0;
}

// Move vertically
y += vspd;


Key Pressed event to switch chars is this:

/// @desc Swap Chars

instance_create_layer(x, y,0, obj_Angry);

instance_destroy();
 

poliver

Member
1.
GML:
if (!place_meeting(x+sign(hspd) * difference_between_masks, y, obj_solid)) {
    instance_create_layer(x, y, 0, obj_Angry);
    instance_destroy();
}
2.
GML:
 if (place_meeting(x+hspd, y, obj_solid)) {
    instance_create_layer(x + difference_between_masks * sign(hspd * -1), y, 0, obj_Angry);
    instance_destroy();
}
something like this i'd say
 

11oyd

Member
Is there a certain way that I need to define difference_between_masks?
I am switching between a 64x64 pixel mask to a 72x72 pixel mask but if I substitute 8 where you have placed difference_between_masks, it means I can only transform in the very centre of the room.

I am using the second option by the way.
 
Top