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

You are not connected. Please login or register

Unity Ninja Unity 3D Forum » FREE Project Downloads & Recources » Scripts » Jet Pack script

Jet Pack script

Go down  Message [Page 1 of 1]

1 Jet Pack script on Wed Aug 20, 2014 3:02 am

Ninjaboy follower

Member [Lv. 3]
Member [Lv. 3]
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

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;

View user profile

2 Re: Jet Pack script on Wed Aug 20, 2014 5:10 am



View user profile http://masterdevelopers.altervista.org/

3 Re: Jet Pack script on Wed Aug 20, 2014 5:28 am


Member [Lv. 3]
Member [Lv. 3]

View user profile

4 Re: Jet Pack script on Mon Nov 06, 2017 10:44 am


Member [Lv. 0]
Member [Lv. 0]
Thanks. Really I needed something like that.

View user profile

Sponsored content

Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum