So ever since Tutorial 4 of this set here: http://walkerboystudio.com/html/unity_course_lab_4.html
My Mario Sprite has been flying straight up with no stop, when I click the jump button (Space Bar) instead of going up and comming down. Though the walkJump and the runJump isn’t working (flying straight up) the crouch jump and just the Jump with no movement is working for some strange reason. I am really stuck at the moment and am questioning what I have done wrong. Is it possible that anyone could help me? Here is the script:
var walkSpeed : float = 1.5; // speed of the standerd walk
var runSpeed : float = 2.0; // speed of the run
var fallSpeed : float = 2.0; // speed of falling down
var walkJump : float = 0.1; // jump height from walk
var runJump : float = 0.0; // jump height from run
var crouchJump : float = 10.0; // jump height from crouching
var gravity : float = 20.0; // force applied on character
var startPos : float = 0.0; // location for start position
var moveDirection : int = 0; // Direction that player faces start
private var velocity : Vector3 = Vector3.zero; // Speed of player and direction
function Update ()
{
var aniPlay = GetComponent ( “aniSprite”);
//aniPlay.aniSprite ( 16, 16, 0, 1, 16, 12);
var controller : CharacterController = GetComponent( CharacterController );
if ( controller.isGrounded )
{
velocity = Vector3 ( Input.GetAxis ( “Horizontal” ), 0, 0 );
}
if ( velocity.x == 0 moveDirection == 1 ) //idle right
{
aniPlay.aniSprite ( 16, 16, 0, 0, 16, 12); // animation to call sprite sheet
}
if ( velocity.x == 0 moveDirection == 0 ) // idle left
{
aniPlay.aniSprite ( 16, 16, 0, 1, 16, 12); // animation to call sprite sheet
}
if ( velocity.x < 0 ) // walk left
{
velocity *= walkSpeed; // move left based on walk speed
aniPlay.aniSprite ( 16, 16, 0, 3, 10, 15 );
}
if ( velocity.x > 0 ) // walk right
{
velocity *= walkSpeed; // move right based on walk speed
aniPlay.aniSprite ( 16, 16, 0, 2, 10, 15 );
}
if ( velocity.x < 0 Input.GetButton ( “Fire1” ) ) // run left
{
velocity *= runSpeed; // move/run left based on run speed
aniPlay.aniSprite ( 16, 16, 0, 5, 16, 24 );
}
if ( velocity.x > 0 Input.GetButton ( “Fire1” ) ) // run right
{
velocity *= runSpeed; // move/run right based on run speed
aniPlay.aniSprite ( 16, 16, 0, 4, 16, 24 );
}
if ( velocity.x == 0 Input.GetAxis ( “Vertical” ) < 0 )
{
if ( moveDirection == 0 ) // idle left
aniPlay.aniSprite ( 16, 16, 0, 9, 16, 24 );
if ( moveDirection == 1 ) // idle right
aniPlay.aniSprite ( 16, 16, 0, 8, 16, 24 );
}
if ( Input.GetButtonDown ( “Jump” ) ( !Input.GetButton ( “Fire1” ) || Input.GetButton ( “Fire1” ) velocity.x == 0 ) Input.GetAxis ( “Vertical” ) >= 0 )
{
velocity.y = walkJump;
}
if (Input.GetButtonDown ( “Jump” ) Input.GetButton ( “Fire1” ) velocity.x != 0 )
{
velocity.y = runJump;
}
if ( Input.GetButtonDown ( “Jump” ) velocity.x == 0 Input.GetAxis ( “Vertical” ) < 0 )
{
velocity.y = crouchJump;
}
if ( !controller.isGrounded )
{
velocity.x = Input.GetAxis ( “Horizontal”);
velocity.x *= walkSpeed;
}
if ( velocity.x < 0 ) //get last move direction- left
{
moveDirection = 0; // set moveDirection to left
}
if ( velocity.x > 0 ) //get last move direction to right
{
moveDirection = 1; // set moveDirection to right
}
velocity.y -= gravity * Time.deltaTime; // apply gravity
controller.Move ( velocity * Time.deltaTime ); // move the controller
}
I really don’t know why the jump feature isn’t working proparly. Can someone please take the time to answer my question!
Thanks ![]()