Flipping the wall jump ability? (Making it available for both sides)
by Orion the Hunter · in Torque Game Builder · 10/26/2012 (8:57 am) · 5 replies
From : www.garagegames.com/community/forums/viewthread/123529/1#comment-811232
I added a wall jump/slide function. However, it only works on walls to the left. Could someone edit the code and flip it around? Because on the right side I flash in and out of glide and fall really fast. I do go slower but I don't have the ability to jump.
I added a wall jump/slide function. However, it only works on walls to the left. Could someone edit the code and flip it around? Because on the right side I flash in and out of glide and fall really fast. I do go slower but I don't have the ability to jump.
#2
10/29/2012 (10:04 am)
Hello, I have found an alternitave way to wall jump to the right. I Glide in to the wall and press "D" (Right). I don't need to do that on the other side. Also, its hard and inconvenient. Could you make it so it's the same on the left as it is on the right? I just jump in to the wall and it lets me slowly slide down. I can't slide on the right. Here is the original post from the link: (See next post)
#3
07/06/2011 (1:36 pm)
10/29/2012 (10:05 am)
#1107/06/2011 (1:36 pm)
Quote:OK, think I got this working fine now.
Full code for non-Pro version.
1) Change the function pskActor::onCollision in ActorMethods.cs
function pskActor::onCollision( %ourObject, %theirObject, %ourRef, %theirRef, %time, %normal, %contacts, %points ) { // If we've hit an enemy, do a few specific checks %aiController = %theirObject.getBehavior( AIControllerBehavior ); if ( %aiController ) { %ourObject.resolveEnemyCollision( %theirObject, %normal ); } // If we've hit a platform, do a few specific checks if (%theirObject.getBehavior(PlatformBehavior)){ if (!%ourObject.onGround){ // Are we against a wall %groundSurface = (%normal.Y < %ourObject.GroundCheckMaxNormal); if (!%groundSurface && mAbs(%normal.X) > 0){ // Tell our owner that there was a wall, if it needs to do anything if (%ourObject.isMethod("hitWall")){ %ourObject.hitWall(%theirObject, %normal); } } } } }2) Add new functions PlayerClass::hitWall, PlayerClass::executeFallAgainstWallAnimationState and PlayerClass::initAnimationStates to PlayerMethods.cs
/// Called when a player collides with a wall. function PlayerClass::hitWall( %ourObject, %theirObject, %normal ) { if (%ourObject.onGround) { %ourObject.onWall = false; } else { //Only change to FallAgainstWall when we are falling. if (getWord( %ourObject.LinearVelocity, 1) > 0){ //Reset jump so we can jump off the wall if ( %ourObject.onWall != true ){ %ourObject.jump = false; } %ourObject.onWall = true; //Get direction of platform if ( %theirObject.getPosition.X > %ourObject.getPosition.X){ %ourObject.onWallDirection = 1; } else { %ourObject.onWallDirection = -1; } %ourObject.setAnimationState( "FallAgainstWall" ); } } } function PlayerClass::initAnimationStates( %this ) { // Register Animation States %this.registerAnimationState( "fallAgainstWall", "CavemanFallAgainstWallAnimation", "" ); } function PlayerClass::executeFallAgainstWallAnimationState(%this) { if (%this.onGround) { %this.onWall = false; if (%this.Direction.X == 0){ return "idle"; } else { return "run"; } } else { if (%this.onWall == true){ //Check if we have jumped since hitting the wall if (%this.jump){ // Bounce the player %this.onWall = false; if (%this.Direction.X == 1){ %this.bounce( %this.JumpForce, 90 + 45 ); } else { if (%this.Direction.X == -1){ %this.bounce( -%this.JumpForce, 45 ); } } return "jump"; } else { //Check our direction if ( %this.Direction.X == -%this.onWallDirection){ //We are no longer touching the wall. %this.onWall = false; return "glide"; } else { //Slow down the player decent. if (getWord( %this.LinearVelocity, 1) > 20){ %this.setLinearVelocityY(mClamp(getWord( %this.LinearVelocity, 1), 0, 20)); } } } } else { %this.onWall = false; if (%this.jump){ return "jump"; } else { return "glide"; } } } return NULL; }
3) Add your new CavemanFallAgainstWall Animation to your project. I just used one that already existed. The first frame from CavemanDamageImageMap, but i'm sure you can do a lot better than that.
NOTE: I'm using the Caveman actor so you may need to change this to Dragon in the code's PlayerClass::initAnimationStates function and the animation name in your project to match.
Thats it, or the best I can do with the little time I have. :D
#4
Add this bold code, in the else Statement, inside the if Statement, in checking of direction, and your problem will be solved =)
%this.Direction.X == %this.onWallDirection && %this.Direction.X == -%this.onWallDirection
10/30/2012 (4:45 am)
Hello, I discovered the solution to this problem, is easy:Add this bold code, in the else Statement, inside the if Statement, in checking of direction, and your problem will be solved =)
%this.Direction.X == %this.onWallDirection && %this.Direction.X == -%this.onWallDirection
function CidClass::executeFallAgainstWallAnimationState(%this)
{
if ( %this.onGround )
{
%this.onWall = false;
if (%this.Direction.X == 0)
{
return "idle";
}
else
{
return "run";
}
}
else
{
if ( %this.onWall == true )
{
//Check if we have jumped since hitting the wall
if ( %this.jump )
{
// Bounce the player
%this.onWall = false;
if (%this.Direction.X == 1)
{
%this.bounce( %this.JumpForce, 90 + 45 );
}
else
{
if ( %this.Direction.X == -1 )
{
%this.bounce( -%this.JumpForce, 45 );
}
}
return "jump";
}
else
{
//Check our direction
if ( [Add this bold code here!] )
{
//We are no longer touching the wall.
%this.onWall = false;
return "glide";
}
else
{
//Slow down the player decent.
if ( getWord( %this.LinearVelocity, 1 ) > 20 )
{
%this.setLinearVelocityY( mClamp( getWord( %this.LinearVelocity, 1 ), 0, 20 ));
}
}
}
}
else
{
%this.onWall = false;
if ( %this.jump )
{
return "jump";
}
else
{
return "glide";
}
}
}
return NULL;
}
#5
Thanks! You guys fixed the problem! It's really helpful when people are clear like that. :)
One more question: The player in the game can be a Caveman and a Dragon, depending on the level. Could you add an "IF" statement that says something like this?
I've already registered the FallAgainstWall_Inverse animation, so no need to worry about that.
10/30/2012 (3:59 pm)
Hi,Thanks! You guys fixed the problem! It's really helpful when people are clear like that. :)
One more question: The player in the game can be a Caveman and a Dragon, depending on the level. Could you add an "IF" statement that says something like this?
if( Player = "Caveman" ){
%ourObject.setAnimationState( "FallAgainstWall_Inverse" );
{I've already registered the FallAgainstWall_Inverse animation, so no need to worry about that.
Torque Owner Kevin James
I've implemented my own platformer from scratch which also includes wall jumping and sliding.
I'm totally unfamiliar with the actual code of PSK. I used invisible scene objects as "sensors" on the front, back, top and bottom of my player collision polygon. When my player changes direction, I flip the player animated sprite which flips the front and back sensors. Then in wall jump code, you just change which direction the jump propels the player.
I suspect that you player is jumping, but jumping into the wall so it just looks like the code is failing.