J
Jmarlin3
Guest
I'm having trouble with one object operating based on what another does correctly.
Here's what it's supposed to do:
Based on the direction of what obj_player is facing, obj_player_head should travel that direction when the 'Z' button is pressed.
Code for Obj_player:
And here's the code for obj_player_head:
I tried to have based on obj_player.move is set as. From my understanding, based on the number .move returns (-1 or 1), obj_player_head should move that direction as well. What am I missing here?
Here's what it's supposed to do:
Based on the direction of what obj_player is facing, obj_player_head should travel that direction when the 'Z' button is pressed.
Code for Obj_player:
Code:
/// Movements
//Get the player's inputs
//all of these return 1 or 0
key_right = keyboard_check(vk_right);//red means it's a constant
key_left = -keyboard_check(vk_left);//the '-' is there to return the negative of the
//original value
key_jump = keyboard_check_pressed(vk_space); //pressed means you have to pressed
//every single time
key_down = keyboard_check(vk_down);
//React to inputs
move = key_left + key_right; // based off numbers returned, that determines if move left or right
hsp = move * movespeed; //number returned from move times movespeed
if (vsp < 10) vsp += grav; //adds vsp to grav once it's less than 10 pixels
if (place_meeting(x,y+1,obj_wall)) //if one pixel below obj_player there is a wall
{
if (key_jump) vsp = -jumpspeed //sets to 0
}
//Horizontal Collision
if (place_meeting(x+hsp,y,obj_wall))
{
while(!place_meeting(x+sign(hsp),y,obj_wall))
{
x += sign(hsp);//sign returns 1 or -1 based
//if hsp is positive or negative
}
hsp = 0; //stops moving
}
//Vertical Collision
if (place_meeting(x,y+vsp,obj_wall))
{
while(!place_meeting(x,y+sign(vsp),obj_wall))
{
y += sign(vsp);//sign returns 1 or -1 based
//if vsp is positive or negative
}
vsp = 0; //stops moving
}
x += hsp; //add horizontal speed to x
y += vsp; //add vertical speed to y
//Animate
//this means if move is either 1 or -1, it flip the sprite vertically in that direction
if (move != 0) image_xscale = move;
Code:
/// @description Insert description here
// You can write your code in this editor
//while head is less than 150, keep adding to x
//when z is held, increase x axis
//when x axis is 150, set hsp back to 0
//keyboard_key = keyboard_check_pressed(ord("Z"));
if (keyboard_check_pressed(ord("Z")))
{
if (obj_player.move == -1){
movespeed = -1 * movespeed
hsp = movespeed
}
else if (obj_player.move == 1){
movespeed = 1 * movespeed
hsp = movespeed
}
//else if (obj_player.image_xscale == 1){
//movespeed = obj_player.image_xscale * movespeed
//hsp = movespeed
//}
x += hsp; //add horizontal speed to x
}
//else
//{
//x = obj_player.x;
//y = obj_player.y;
//}