how to fix my collusion with the floor / wall?

M

manouijpelaar

Guest
I am working on a assignment for school to make a game and I putted some code in different events, but when I run the game my player doesn't have his 'feet' on the ground

I have used the code in these videos:

in the create event I have this:

hspeed_ = 0;
max_hspeed_ = 4;
vspeed_ = 0;
gravity_ = 0.5;
acceleration_ = 1;
friction_ = .3;
jump_height_ = -10;

// Map keys
keyboard_set_map(ord("W"), vk_up);
keyboard_set_map(ord("A"), vk_left);
keyboard_set_map(ord("S"), vk_down);
keyboard_set_map(ord("D"), vk_right);

in the step event I have this:

var hinput = keyboard_check(vk_right) - keyboard_check(vk_left);

if hinput != 0 {
hspeed_ += hinput*acceleration_;
hspeed_ = clamp(hspeed_, -max_hspeed_, max_hspeed_);
} else {
hspeed_ = lerp(hspeed_, 0, friction_);
}

if !place_meeting(x, y+1, objGrotto_platform) {
vspeed_ += gravity_;
} else {
if keyboard_check(vk_up) {
vspeed_ = jump_height_;
}
}

// horizontal
if (place_meeting(x+ hspeed_,y,objGrotto_platform))
{
while (!place_meeting(x+sign(hspeed_),y,objGrotto_platform))
{
x = x + sign(hspeed_);
}
hspeed_ = 0;
}
x += hspeed_;

// vertical
if (place_meeting(x,y+ vspeed_,objGrotto_platform))
{
while (!place_meeting(x,y+sign(vspeed_),objGrotto_platform))
{
y = y + sign(vspeed_);
}
vspeed_ = 0;
}
y += vspeed_;

in the draw event I have this:

//Draw Player and Power orb
var dir = point_direction(x, y, mouse_x, mouse_y);
var flipped = (mouse_x < x)*2-1;

//Draw Player
draw_sprite_ext(objEle, 0, x, y, flipped, 1, 1, image_blend, image_alpha);

//Draw Power orb
draw_sprite_ext(Power_orb, 0, x, y, 1, flipped, dir, image_blend, image_alpha);
 

Attachments

Sidorakh

Member
Does your player object have a mask? If so, then either the mask si the wrong size, or the origin of the player sprites and masks are wrong. You'll want to check both of these.
 
M

manouijpelaar

Guest
yes
Does your player object have a mask? If so, then either the mask si the wrong size, or the origin of the player sprites and masks are wrong. You'll want to check both of these.
I used a custom origin, because of the 'gun' it is carying (the orb in the middle) but Í dont know what the masks are actually.
 

Sidorakh

Member
You'll want to check your object window, below Sprite there should be somethign that says Mask. Whatever that box says is the mask.

For example, here's a screenshot of an object from a game I'm working on: https://i.imgur.com/8c8NEW7.png

The sprite is set to spr_npc_child_girl_idle and the mask is set to spr_player_Default
 
M

manouijpelaar

Guest
You'll want to check your object window, below Sprite there should be somethign that says Mask. Whatever that box says is the mask.

For example, here's a screenshot of an object from a game I'm working on: https://i.imgur.com/8c8NEW7.png

The sprite is set to spr_npc_child_girl_idle and the mask is set to spr_player_Default
well my mask is the same as the sprite, but my sprite is a little big, does it have something to do with that maybe? or is it really the origin?
 

Attachments

M

manouijpelaar

Guest
You'll want to check your object window, below Sprite there should be somethign that says Mask. Whatever that box says is the mask.

For example, here's a screenshot of an object from a game I'm working on: https://i.imgur.com/8c8NEW7.png

The sprite is set to spr_npc_child_girl_idle and the mask is set to spr_player_Default
I sort of solved the problem with using another sprite, but it is still not optimal, but I can go along with it
 
Top