FragMate CommunityLog in

FragMate - Software and Game Developer Community, including Resources, Forums, Marketplace & More.

Share

descriptionJet Pack script

more_horiz
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;
            }
   }
}

descriptionRe: Jet Pack script

more_horiz
Nice

_________________
Game Developer
YouTube Channel: [You must be registered and logged in to see this link.]
Website: [You must be registered and logged in to see this link.]

descriptionRe: Jet Pack script

more_horiz
Thanks

descriptionRe: Jet Pack script

more_horiz
Thanks. Really I needed something like that.
Permissions in this forum:
You cannot reply to topics in this forum