Unity Ninja Unity 3D Forum
To have exclusive access to all downloads, recourses and links within this forum, a free registered account is required. Just a heads up Wink
Share
Go down
Member [Lv. 3]
Member [Lv. 3]
Posts : 37
Points : 1642
Rep : 19
Join date : 2014-06-14
View user profile

Jet Pack script

on Wed Aug 20, 2014 3:02 am
This script came as a request from one of the guys on this forum. What it actually does (suppose to do) is by assuming the player has a jet pack on, by pressing "F" the player would fly for a limited period of time.
1: Make sure your player has a rigidbody attached.
2: Name the script as "JetPack", without the quotes.
3: Create an empty game object and attach the following script to it.
4:There are some variables to fill out....
Jet Pack Force = is the force by which the jet pack pushes the player upward.
Start Time = is how long the player stays floating in the air by default it is 3.5 seconds but you can edit it.
Player = obviously the player Very Happy
Code:

using UnityEngine;
using System.Collections;

public class JetPack : MonoBehaviour {

   public float JetPackForce;
   public float startTime = 3.5f;
   public GameObject player;
   void Start(){
      }
   void FixedUpdate () {
      if (Input.GetKey (KeyCode.F)) {
         startTime -= Time.deltaTime;
         player.rigidbody.AddForce(new Vector3(0.0f, 1.0f, 0.0f) * JetPackForce);
            }
      if (startTime <= 0.0f) {
         player.rigidbody.velocity = Vector3.down * Time.smoothDeltaTime;
         startTime = 3.5f;
            }
   }
}

avatar
Moderator
Moderator
Posts : 329
Points : 2177
Rep : 43
Join date : 2014-03-12
Age : 18
Location : Italy
View user profilehttp://masterdevelopers.altervista.org/

Re: Jet Pack script

on Wed Aug 20, 2014 5:10 am
Nice
Member [Lv. 3]
Member [Lv. 3]
Posts : 18
Points : 1666
Rep : 1
Join date : 2014-01-27
View user profile

Re: Jet Pack script

on Wed Aug 20, 2014 5:28 am
Thanks
Member [Lv. 0]
Member [Lv. 0]
Posts : 1
Points : 259
Rep : 0
Join date : 2017-11-06
View user profile

Re: Jet Pack script

on Mon Nov 06, 2017 10:44 am
Thanks. Really I needed something like that.
Back to top
Permissions in this forum:
You cannot reply to topics in this forum