- Home /
Jump Boost
Hi, I am new to Unity and I'm currently doing the roll-a-ball thing but i wanted to add a few things in. I wanted to add a jump booster and I want it to work so that when I touch it, it launches me up into the air. I've tried looking at other Questions but none of them seem to be like this. This is the code I have right now:
using UnityEngine; using System.Collections;
public class Control : MonoBehaviour {
public float speed;
public float boostHeight;
private Rigidbody rb;
void Start () { rb = GetComponent(); }
void FixedUpdate () {
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement * speed);
void OnTriggerEnter (Collider other)
{
if (other.gameObject.CompareTag ("Jumpboost"))
{
rb.Addforce (0,boostHeight,0);
}
}
}
}
Your answer
Follow this Question
Related Questions
How may I observe expected physical interactions while using Rigidbody.MoveRotation()? 1 Answer
Collision interpenetration and object getting stuck 1 Answer
Non-convex MeshCollider with non-kinematic Rigidbody? 2 Answers
How do I "remove/disable" collision? 3 Answers
Camera and mesh not colliding 1 Answer