- Home /
prevent my rigidbody from going through the floor when it jumps and comes down
i was able to put a script together through research on the movement and jumping of a rigidbody...but i noticed that anytime i jump up and i try to come down, i go through the stationary platform beneath me...the platform moves with my rigidbody and i want my rigidbody to stand on my stationary platform anytime it comes down after jumping up...here is my script
pragma strict
var playerSpeed: float; var projectilePrefab : GameObject; private var speed : float = 0.5f; //private var JumpHeight : int = 30.0; var JumpSpeed : float = 25.0f; var JumpStrength : float = 0.3; var JumpDecay : float = 0.01; var Jumped : boolean = false;
function Jump() { animation.Play("timi"); rigidbody.AddForce(Vector3.up *JumpSpeed );
}
function Update() {
if (Input.GetKey(KeyCode.RightArrow))
this.transform.position += Vector3.right * speed;
if (Input.GetKey(KeyCode.LeftArrow))
this.transform.position += Vector3.left * speed;
if (this.Jumped){
this.transform.position.y += this.JumpStrength - this.JumpDecay;
this.JumpDecay += 0.009; }
if(Input.GetKeyDown(KeyCode.UpArrow)){
this.Jumped = true;
Jump();
}
transform.position.x = Mathf.Clamp(transform.position.x, -545, -435);
//to shoot bullets using the jump key
if(Input.GetButtonDown("Jump")){ Instantiate(projectilePrefab, transform.position, Quaternion.identity); }
}
Your answer
Follow this Question
Related Questions
Dash in movement direction, not in forward direction 0 Answers
Player clipping through floor? 1 Answer
Any instruments for city leveling 0 Answers