- Home /
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! :)
Your answer
Follow this Question
Related Questions
Change Web Player Size? 1 Answer
how big is my app size 2 Answers
How do I change the size & position of the standalone player in windows? 0 Answers
Textures sizes Web/PC vs iOS. 1 Answer
Texture size 2 Answers