Legacy GM How would I script a ledge animation?

T

Tsumuri

Guest
In my game, I have an animation prepared that I want to have played when the character is on the edge of a ledge, but only if the drop is larger than a specific amount.



Very similar to how Sonic plays this animation when he's near a ledge, but in my case, I don't want it to play when I have a drop of only one player height.



Like this.

Thanks in advance for any help provided.
 
L

LilRony

Guest
if your collision code is set up the right way, I believe you could call something like this:

Code:
var facing = 1; // consider if the player is facing right (1) or left (-1). in this case, lets say it's to the right.
if (!place_meeting(x + 32 * facing, y + 1, obj_wall)) { // now with the "x + 32*facing", that basically means that its seeing ahead of the player 32 pixels, and if facing were -1, it would become -32 pixels, so it'd be checking the left in that case.
// also note the y + 1 and the "!" before place_meeting. This means it's checking if the player WOULD NOT be touching a wall if he were 32 pixels ahead and 1 pixel down.  
     sprite_index = spr_wabble; // so if all this is true, then set the wabble sprite.
}else{sprite_index = spr_idle}
also note that you can change the 32 pixels to be any distance. this is especially necessary if the player sprite is a different size. I'd experiment with it.

Hope this works :)
 

obscene

Member
You could cheat if you'd like and make a ledge object that you place in areas where this would happen. I actually do this to make climbable ledges instead of trying to code the physics of it. Easier IMO and prevents me from accidentally making climbable areas and such.

Plan B, this script is useful for gauging distance... http://www.gmlscripts.com/script/range_finder Check from player's front edge straight down and if it's over a certain amount, play the animation.
 
T

Tsumuri

Guest
if your collision code is set up the right way, I believe you could call something like this:

Code:
var facing = 1; // consider if the player is facing right (1) or left (-1). in this case, lets say it's to the right.
if (!place_meeting(x + 32 * facing, y + 1, obj_wall)) { // now with the "x + 32*facing", that basically means that its seeing ahead of the player 32 pixels, and if facing were -1, it would become -32 pixels, so it'd be checking the left in that case.
// also note the y + 1 and the "!" before place_meeting. This means it's checking if the player WOULD NOT be touching a wall if he were 32 pixels ahead and 1 pixel down.
     sprite_index = spr_wabble; // so if all this is true, then set the wabble sprite.
}else{sprite_index = spr_idle}
also note that you can change the 32 pixels to be any distance. this is especially necessary if the player sprite is a different size. I'd experiment with it.

Hope this works :)

This looks almost right, but from what I'm seeing, it looks like the script is searching horizontally for any possible collisions, when it should be searching vertically.

You could cheat if you'd like and make a ledge object that you place in areas where this would happen. I actually do this to make climbable ledges instead of trying to code the physics of it. Easier IMO and prevents me from accidentally making climbable areas and such.

Plan B, this script is useful for gauging distance... http://www.gmlscripts.com/script/range_finder Check from player's front edge straight down and if it's over a certain amount, play the animation.
I was actually considering this at first, since I'm garbage at programming. But this means I have to manually place one on every long drop, of which there are a lot.
I'll check out that script to see if I can use it.
 
L

LilRony

Guest
This looks almost right, but from what I'm seeing, it looks like the script is searching horizontally for any possible collisions, when it should be searching vertically.
It actually is searching vertically. In the place_meeting check, it checks x + (32*facing) and that's combined with checking y + 1. Basically, it is hypothetically puting the player 32px ahead, and 1px down. if the player were to become stuck in a wall in that case, he would not need to play the wabble animation. however, if the player were to start falling at that position, he should indeed start playing the animation.

EDIT: I understand what you actually want now. in that case, you should check y + [block height]. it works the same way. Do note that the player will likely start playing the animation on a terrain that is 1 block thick. In that case, I'd first check place_meeting(x + 32*facing, y + 1, solid) and if that returns true, check place_meeting(x + 32*facing, y + [blockheight], solid).
 
Top