i am working on 2d game . . . .i want that when my 2d player got jetpack it remain in air or in jump condition for a moment, then my player sit in jet and the level end. . . can you tell me plz…how to remain my player above the ground for just for 3 second? here’s script. …
pragma strict
var columnsize :int = 19; var rowsize :int= 1 ; var columnframestart :int = 1; var rowframestart :int = 0 ; var totalframes :int = 19 ; var framesPersecond :int = 22 ;
var speed : float = 4; var jumpSpeed : float = 3; var gravity : float = 20.0; var JMPVectorSpeed :int = 3 ;
var coin : int =0; var player : GameObject ; private var moveDirection : Vector3 = Vector3.zero;
function Start () {
}
function FixedUpdate() {
var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded)
{
// We are grounded, so recalculate
// move direction directly from axes
moveDirection = Vector3(1, 0,0);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
var anim = gameObject.GetComponent(spriteScript);
anim.sprite( columnsize, rowsize , columnframestart , rowframestart , totalframes , framesPersecond );
// sprite(columnsize , rowsize , columnframestart , rowframestart , totalframes , framesPersecond );
if (Input.touchCount > 0)
{
print (Input.GetTouch(0));
var touch : Touch = Input.GetTouch(0);
if (touch.position.x < Screen.width/2) { //jump(controller); } else if (touch.position.x > Screen.width/2) { jump(controller); } }
if (Input.GetButton ("Jump"))
{
jump(controller);
}
}
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
controller.Move(moveDirection * Time.deltaTime);
/JumpDown/
JumpDown();
if( Input.GetKeyDown(KeyCode.Escape) )
{
Application.LoadLevel(0);
}
}
function jump(controller : CharacterController) { moveDirection.y = jumpSpeed; // transform.Translate( Time.deltaTime * -Vector2.right * JMPVectorSpeed * controller.velocity.x); transform.TransformDirection( Time.deltaTime * -Vector2.right * JMPVectorSpeed * controller.velocity.x);
controller.Move( Time.deltaTime * -Vector2.right * JMPVectorSpeed * controller.velocity.x );
}
function JumpDown() { if( player.transform.position.y < 3 ) { //transform.position = Vector3(0.5973034,10.15439,5.695408); Application.LoadLevel(0);
}
}