Jump to content


Photo

Climbing Problem


  • Please log in to reply
4 replies to this topic

#1 GrayCircle

GrayCircle

    GMC Member

  • GMC Member
  • 26 posts
  • Version:GM8

Posted 13 February 2012 - 02:47 AM

I am posting a climbing animation and it doesn't stop its animation when collided with the ladder when their is no keys pressed:
Step Event:
if place_meeting(x,y,Ladder)
{
gravity_direction = 270;
gravity = 0;
if keyboard_check(vk_up) || keyboard_check(vk_down) || keyboard_check(vk_right) || keyboard_check(vk_left)
{
sprite_index = climb;
image_speed = .5;
image_index = sprite_index;
}
else
if !(keyboard_check(vk_up)) and (keyboard_check(vk_down)) and !(keyboard_check(vk_right) and keyboard_check(vk_left))
{
sprite_index = climb;
image_speed = 0;
image_index = 0;
}
if !keyboard_check(vk_up) and !keyboard_check(vk_down) && (vspeed>0 or vspeed<0)
{
vspeed = 0
}
if !keyboard_check(vk_up) and !keyboard_check(vk_down) && (hspeed>0 or hspeed<0)
{
hspeed = 0
}
Any thing wrong?
  • 0

#2 greep

greep

    Menaces with Spikes

  • GMC Member
  • 2398 posts
  • Version:GM7

Posted 13 February 2012 - 02:53 AM

I am posting a climbing animation and it doesn't stop its animation when collided with the ladder when their is no keys pressed:
Step Event:

if place_meeting(x,y,Ladder)
{
gravity_direction = 270;
gravity = 0;
if keyboard_check(vk_up) || keyboard_check(vk_down) || keyboard_check(vk_right) || keyboard_check(vk_left)
{
sprite_index = climb;
image_speed = .5;
image_index = sprite_index;
}
else
if !(keyboard_check(vk_up)) and (keyboard_check(vk_down)) and !(keyboard_check(vk_right) and keyboard_check(vk_left))
{
sprite_index = climb;
image_speed = 0;
image_index = 0;
}
if !keyboard_check(vk_up) and !keyboard_check(vk_down) && (vspeed>0 or vspeed<0)
{
vspeed = 0
}
if !keyboard_check(vk_up) and !keyboard_check(vk_down) && (hspeed>0 or hspeed<0)
{
hspeed = 0
}
Any thing wrong?


This:

if !(keyboard_check(vk_up)) and (keyboard_check(vk_down)) and !(keyboard_check(vk_right) and keyboard_check(vk_left))

is unnecessary, just make it an else, not else if. Logically, either you are holding a key (the initial if statement), or you are not.

Edit: Additionally, there is also no real need for && (vspeed>0 or vspeed<0) or && (hspeed>0 or hspeed<0). I think removing it is better for processing speed, but Not entirely sure.

Edited by greep, 13 February 2012 - 02:57 AM.

  • 0

#3 kupo15

kupo15

    GMC Member

  • GMC Member
  • 661 posts
  • Version:GM8.1

Posted 13 February 2012 - 03:20 AM

If the speed checks are needed, vspeed != 0 would be more condensed
  • 0

#4 GrayCircle

GrayCircle

    GMC Member

  • GMC Member
  • 26 posts
  • Version:GM8

Posted 13 February 2012 - 10:31 PM

I have another problem similar to the topic when I hold the "up" key:
{
if !position_meeting(x,y,Ladder)
{
jump+=2;
if jump<3 and jump!=0  // if you have jumped less then 3 times without touching the ground and you can do stuff.
{
gravity = 1;
vspeed=-7; // vspeed   -=7 makes you go up at a speed of 10
if jump>0 //if variable, jump, is more than the value 0
{
jump-=1
}
}
}
if facingright = true
{
sprite_index= jump_right // your sprite is jumpsprite (see create event)
jumping = true // yes you are jumping
}
else
{
sprite_index = jump_left
jumping = true
}
}
It changes to its "jump" animation instead of turning into its "climbing" animation. How is this possible an what is recognized to be changed here?

Edited by GrayCircle, 13 February 2012 - 10:33 PM.

  • 0

#5 greep

greep

    Menaces with Spikes

  • GMC Member
  • 2398 posts
  • Version:GM7

Posted 14 February 2012 - 12:30 AM

position_meeting should be place_meeting, but other than that, I can't tell.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users