Hello, I am having trouble modifying my movement script for my 2d game.
Jumping is doing well but not as fluid. I was just wondering how/what formula should I use to create a parabolic jumping motion?
// Control Scheme:
// Left - A, Left Arrow
// Right - D, Right Arrow
// Crouch - S, Down Arrow
// Run - Shift + Move
// Jump - Spacebar
// Run Jump - Shift + Move + Jump
// Crouch Jump - Down + Jump
var walkSpeed : float = 1.5; // speed of standard walk
var runSpeed : float = 2.0; // speed of run
var walkJump : float = 6.2; // speed of falling down
var runJump : float = 20.0; // jump height from walk
var crouchJump : float = 10.0; // jump height from run
var fallSpeed : float = 2.0; // jump height from crouch
var gravity : float = 20.0; // force applied on char
var startPos : float = 0.0; // location for start position
var moveDirection : int = 1; // direction player facing
var spawnPoint : Transform; // spawn point inherited from Spawn Object
private var velocity : Vector3 = Vector3.zero; // speed of player and direction
function Update ()
{
var controller : CharacterController = GetComponent( CharacterController );
var aniPlay : exSpriteAnimation = GetComponent("exSpriteAnimation");
if ( controller.isGrounded )
{
velocity = Vector3 ( Input.GetAxisRaw ("Horizontal"), 0 , 0 );
//velocity = transform.InverseTransformDirection ( velocity );
//velocity *= walkSpeed;
if ( velocity.x == 0 && moveDirection == 1 ) // idle right
{
if (!aniPlay.IsPlaying("nbreatheright"))
{
aniPlay.Play ( "nbreatheright" );
} // animation to call sprite sheet
}
if ( velocity.x == 0 && moveDirection == 0 ) // idle left
{
if (!aniPlay.IsPlaying("nbreatheleft"))
{
aniPlay.Play ( "nbreatheleft" );
} // animation to call sprite sheet
}
if ( velocity.x > 0) // walk right
{
velocity.x = walkSpeed + 25;
if (!aniPlay.IsPlaying("nrunright"))
{
aniPlay.Play ( "nrunright" );
}
}
if ( (velocity.x > 0) && Input.GetButton ( "Fire1" ) ) // sprint right
{
velocity.x = runSpeed + 50;
if (!aniPlay.IsPlaying("nrunright"))
{
aniPlay.Play ( "nrunright" );
}
}
if ( velocity.x < 0) // walk left
{
velocity.x = -(walkSpeed + 25);
if (!aniPlay.IsPlaying("nrunleft"))
{
aniPlay.Play ( "nrunleft" );
}
}
if ( (velocity.x < 0) && Input.GetButton ( "Fire1" ) ) // sprint left
{
velocity.x = -(runSpeed + 50);
if (!aniPlay.IsPlaying("nrunleft"))
{
aniPlay.Play ( "nrunleft" );
}
}
if ( Input.GetButtonDown ( "Jump" ) && !Input.GetButton ( "Fire1" ) && moveDirection == 1 ) // jump right
{
velocity.y = walkJump + 5;
aniPlay.Play ( "njumpright" );
}
if ( Input.GetButtonDown ( "Jump" ) && Input.GetButton ( "Fire1" ) && moveDirection == 1 ) // high jump right
{
velocity.y = runJump + 10;
aniPlay.Play ( "njumpright" );
}
if ( Input.GetButtonDown ( "Jump" ) && !Input.GetButton ( "Fire1" ) && moveDirection == 0 ) // jump left
{
velocity.y = walkJump + 5;
aniPlay.Play ( "njumpleft" );
}
if ( Input.GetButtonDown ( "Jump" ) && Input.GetButton ( "Fire1" ) && moveDirection == 0 ) // high jump left
{
velocity.y = runJump + 10;
aniPlay.Play ( "njumpleft" );
}
}
if ( (!controller.isGrounded ) && !Input.GetButton ( "Fire1" ) )
{
velocity.x = Input.GetAxis ( "Horizontal" );
velocity.x *= walkSpeed + 10;
}
if ( (!controller.isGrounded ) && Input.GetButton ( "Fire1" ) )
{
velocity.x = Input.GetAxis ( "Horizontal" );
velocity.x *= runSpeed + 10;
}
if ( velocity.x < 0 ) // get last move direction
{
moveDirection = 0; // move direction to left
}
if (velocity.x > 0 ) // get last move direction
{
moveDirection = 1; // move direction to left
}
velocity.y -= gravity * Time.deltaTime; // apply gravity
controller.Move ( velocity * Time.deltaTime ); // move the controller
}
function Awake () {
Spawn ();
}
function Spawn () {
// reset the character's position to the spawnPoint
transform.position = spawnPoint.position;
}
function OnDeath () {
Spawn ();
}