- Home /
Power Up speed and jump boost
So I have that problem when I do know how to make those collectibles but I do have problem with power ups. What should I do when I want to make two power ups that make player move faster for couple of seconds and another booster is for thrusting player in the air. What should I start with?
Answer by $$anonymous$$ · Nov 19, 2017 at 04:28 AM
I did this a while ago, and here's what I used:
Jump Boost:
Create and tag your Power-Up: "JumpBoost"
Make Sure that it's collider is checked "IsTrigger"
Add this Script to your Player! (It's in JavaScript, I hope that's okay)
var JumpForce : float = 500; //The Jump Height!
var rb : Rigidbody; //This will be grabbed Automatically!
function OnTriggerEnter (other : Collider)
{ if (other.gameObject.tag == "JumpBoost") //If the Player Touches the Power-Up...
{ rb.AddForce (Vector3.up * JumpForce); //JUMP!! } } function Update () { rb = GetComponent(Rigidbody); }
Keep in mind this script will boost your Player as soon as they touch it. Adding some kind of "power-up holder" is a little more complex, but is still possible.
Speed Boost:
I don't have a script for this one, but use the "OnTriggerEnter" function in your Player Movement Script to allow the player to interact with the power-up. Instead of the power-up adding force up, make it increase the Move Speed, and set a timer using Invoke ("Function Name", time);
Example:
function OnTriggerEnter (other : Collider) {
if (other.gameObject.tag == "SpeedBoost")
{
MoveSpeed = 10;
Invoke ("RegularSpeed", 5);
}
function RegularSpeed ()
{
MoveSpeed = 5;
}
Hope this Helped!!
Answer by PatD17th · Nov 19, 2017 at 01:02 PM
Will this work in C#? What should I put in void Start and what in void Update?
This won't work in C#, but it will if you replace function with void and replace the variables from var JumpForce : float; to public float Jumpforce; and public Rigidbody rb; There's also a Js to C# converter that can really help with these kinds of things! You don't need anything in Start and Update, but you can put the "rb = GetComponent(Rigidbody);" in the Update void to find the rigidbody automatically.
Your answer
Follow this Question
Related Questions
Increase speed of object that enters OnTriggerEnter 1 Answer
Increasing the speed for a few seconds doesn't work. 1 Answer
HELP! With my Speed power up 2 Answers
Increase the speed after collision 0 Answers
Player movement problem 0 Answers