L
Little Coding Wolf
Guest
For some reason my character is not jumping. I have looked around and I believe I am using the right code. I put a debug message to check if I hit the code and I do. Second problem is if I set friction variable it seems to not be doing anything. If I set it under the physics window on object it works. I have no idea what is happening.
Character Base Script
Character Player Input Script
Character Movement Script
Character Base Script
Code:
//Input Variables
xInput = 0;
doJump = false;
//Movement Variables
runSpeed = 6;
jumpForce = -60;
//State Variables
isGrounded = false;
jumpCount = 0;
maxJumpCount = 2;
//Image Variables
imageScale = 1;
//Animation Variables
idleSprite = 0;
runSprite = 0;
inAirSprite = 0;
//Physics variables
groundCheckDistance = 10;
moveFriction = 0;
idleFriction = 999;
//Set in-built physics settings for character
phy_fixed_rotation = true;
phy_active = true;
Code:
//Get our input
keyLeft = keyboard_check(vk_left);
keyRight = keyboard_check(vk_right);
keyJump = keyboard_check_pressed(vk_up);
//Set our horzontal movement speed based on input plus walk speed
xInput = (keyRight - keyLeft) * runSpeed;
//Jump if we are press jump key
if (keyJump)
doJump = true;
Code:
//Get if we are grounded
isGrounded = collision_line(x,y,x,y + groundCheckDistance,collision_object, false,false);
//Jump
{
if (doJump && jumpCount > 1)
{
//Penalty for doing first jump in the air
if (jumpCount == maxJumpCount && !isGrounded)
jumpCount--;
//Substract jump count by one since we jumped
jumpCount--;
physics_apply_local_force(x, y, 0, -60);
show_debug_message("HIT");
}
if (isGrounded)
jumpCount = maxJumpCount;
doJump = false;
}
//Move X
phy_position_x += xInput;
//Set friction based on if we are moving
friction = phy_speed != 0 ? moveFriction : idleFriction;