x


Launching character down, gradually expanding and freezing movement.

Okay, here is the deal. So far I am making a sidescroller game with a main character controlled by A and D (to move to the sides) and W to jump. If the player holds space, time slows down for a bit. I want to add a function though, where the player jumps (using W) and then is able to press S to launch to the ground (maybe making some fancy animation). When the player hits the ground a sphear looking like a bubble quickly but gradually expands from nothing and when it hits a decent size, it freezes all movement inside it (exept for the player). 5 seconds after everything should start moving again and the bubble gradually disapears (like the beginning just reversed). I know that this is alot but i thought it would be such an awesome mechanic and I have really tried to make it myself though i truly suck at scripting (got stuck at the launching down part).

This is the sript that I use to move the character and jump:

var speed = 6.0;

var jumpSpeed = 8.0;

var gravity = 20.0;



private var moveDirection = Vector3.zero;

private var grounded : boolean = false;

private var lastYSpeed : float = 0;



function FixedUpdate() {

   if (grounded)

   {

      // We are grounded, so recalculate movedirection directly from axes

      moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));

      moveDirection = transform.TransformDirection(moveDirection);

      moveDirection *= speed;



      if (Input.GetButton ("Jump")) {

         moveDirection.y = jumpSpeed;

      }



      // On the ground

      lastYSpeed = 0;

   }

   else

   {

      // We are in the air, maintain lastYSpeed

      moveDirection = new Vector3(Input.GetAxis("Horizontal"), lastYSpeed, Input.GetAxis("Vertical"));

      moveDirection = transform.TransformDirection(moveDirection);



      // Remove speed factor from influencing Y value

      moveDirection.x *= speed;

      moveDirection.z *= speed;

   }



   // Apply gravity

   moveDirection.y -= gravity * Time.deltaTime;

   lastYSpeed = moveDirection.y;



   // Move the controller

   var controller : CharacterController = GetComponent(CharacterController);

   var flags = controller.Move(moveDirection * Time.deltaTime);

   grounded = (flags & CollisionFlags.CollidedBelow) != 0;

}



@script RequireComponent(CharacterController)

Thank you so much in advance! :)

more ▼

asked May 15 '12 at 07:00 PM

tahcet gravatar image

tahcet
45 1 3

(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x286
x142
x49
x10
x8

asked: May 15 '12 at 07:00 PM

Seen: 300 times

Last Updated: May 15 '12 at 07:24 PM