D
Daniel Cantu
Guest
Hello, I am new to using Game Maker Studio 2, and programming in general. So far, I looked up tutorials for making a plat former, and I was doing great until the shooting mechanics are off. My character keeps shooting right, even though I'm facing left. Here is all of my code for my Obj_Player, because I'm starting to think that I messed up badly. Thank you for reading my plea. :3
Player Input
key_left = keyboard_check(vk_left);
key_right = keyboard_check(vk_right);
key_jump = keyboard_check_pressed(vk_up);
//Calculate Movement
var move = key_right - key_left;
hsp = move * walksp;
vsp = vsp + grv;
if (place_meeting(x, y+1,Obj_Wall)) && (key_jump)
{
vsp = -7;
}
//Shooting Physics for Platformer(MEGAMAN)
if(keyboard_check_pressed(vk_space)){
with (instance_create_depth(x,y,0,obj_bullet))
speed = 10;
direction = Obj_Player.direction;
image_angle = direction;
}
//Horizontal Collision
if (place_meeting(x+hsp,y,Obj_Wall))
{
while (!place_meeting(x+sign(hsp),y,Obj_Wall))
{
x = x + sign(hsp);
}
hsp = 0;
}
x = x + hsp;
//Vertical Collision
if (place_meeting(x,y+vsp,Obj_Wall))
{
while (!place_meeting(x,y+sign(vsp),Obj_Wall))
{
y = y + sign(vsp);
}
vsp = 0;
}
y = y + vsp;
///Animation
if (!place_meeting(x,y+1,Obj_Wall))
{
sprite_index = Spr_Player_Jump
image_speed = 0;
if (sign(vsp) > 0) image_index = 1; else image_index = 0;
}
else
{
image_speed = 1;
if (hsp == 0)
{
sprite_index = Spr_Player_Idle;
}
else
{
sprite_index = Spr_Player_Moving
}
}
if (hsp != 0) image_xscale = sign(hsp);
Player Input
key_left = keyboard_check(vk_left);
key_right = keyboard_check(vk_right);
key_jump = keyboard_check_pressed(vk_up);
//Calculate Movement
var move = key_right - key_left;
hsp = move * walksp;
vsp = vsp + grv;
if (place_meeting(x, y+1,Obj_Wall)) && (key_jump)
{
vsp = -7;
}
//Shooting Physics for Platformer(MEGAMAN)
if(keyboard_check_pressed(vk_space)){
with (instance_create_depth(x,y,0,obj_bullet))
speed = 10;
direction = Obj_Player.direction;
image_angle = direction;
}
//Horizontal Collision
if (place_meeting(x+hsp,y,Obj_Wall))
{
while (!place_meeting(x+sign(hsp),y,Obj_Wall))
{
x = x + sign(hsp);
}
hsp = 0;
}
x = x + hsp;
//Vertical Collision
if (place_meeting(x,y+vsp,Obj_Wall))
{
while (!place_meeting(x,y+sign(vsp),Obj_Wall))
{
y = y + sign(vsp);
}
vsp = 0;
}
y = y + vsp;
///Animation
if (!place_meeting(x,y+1,Obj_Wall))
{
sprite_index = Spr_Player_Jump
image_speed = 0;
if (sign(vsp) > 0) image_index = 1; else image_index = 0;
}
else
{
image_speed = 1;
if (hsp == 0)
{
sprite_index = Spr_Player_Idle;
}
else
{
sprite_index = Spr_Player_Moving
}
}
if (hsp != 0) image_xscale = sign(hsp);