Solthall
Member
Hello guys!
Any tips on how I can make collisions work with the following movement code? I'm moving the player with w,a,s,d, all relative to the mouse position. So if I press "W", the player moves towards the mouse pointer, and away if I press "S". "A" and "D" will make the player strafe arround the mouse pointer. This is the movement I want to use.
I have had some collisions in place, as you can see. But that only works if movement is set with "x += walkSpeed" and so on, like I tried recently. But that doesn't result in the movement I want.
*Step event (placed in a script)
My player sprite is created in the draw event, so that the mask doesn't rotate with the sprite, and here's the code for that:
*Draw event
First post, so I hope this gives you enough information, I apologize if not. Probably didn't post the code in the correct fashion either.
Any tips on how I can make collisions work with the following movement code? I'm moving the player with w,a,s,d, all relative to the mouse position. So if I press "W", the player moves towards the mouse pointer, and away if I press "S". "A" and "D" will make the player strafe arround the mouse pointer. This is the movement I want to use.
I have had some collisions in place, as you can see. But that only works if movement is set with "x += walkSpeed" and so on, like I tried recently. But that doesn't result in the movement I want.
*Step event (placed in a script)
angle = point_direction(x,y,mouse_x,mouse_y);
direction = angle;
//Movement direction
if (global.shop == false && obj_stairs.alarm[0] == -1)//dont move if shop open
{
if forward and not place_meeting(x,y-5,obj_solid)
{
speed = walkSpeed;
image_speed = 1;
}
if backward and not place_meeting(x,y+5,obj_solid)
{
speed = -walkSpeed;
image_speed = 1;
}
if right and not place_meeting(x+5,y,obj_solid)
{
direction += 90;
speed = -walkSpeed;
image_speed = 1;
}
if left and not place_meeting(x-5,y,obj_solid)
{
direction -= 90;
speed = -walkSpeed;
image_speed = 1;
}
}
// Stop moving when no key is pressed
if keyboard_check(vk_nokey)
{
speed = 0;
image_index = 0;
image_speed = 0;
}
// Stop moving if multiple inputs detected
if left and right
{
speed = 0;
image_index = 0;
image_speed = 0;
}
// Stop moving if colliding with mouse pointer
if point_distance(x,y,mouse_x,mouse_y) < 15
{
speed = 0;
image_index = 0;
image_speed = 0;
}
My player sprite is created in the draw event, so that the mask doesn't rotate with the sprite, and here's the code for that:
*Draw event
draw_sprite_ext(spr_player_idle, 0, x, y, 1, 1, angle, c_white, 1);
First post, so I hope this gives you enough information, I apologize if not. Probably didn't post the code in the correct fashion either.
Last edited: