Jetpack

Hi i’m trying to make a jetpack for my character and i’ve come across two problems.

  1. The script doesn’t work on my player but does on other objects. I think it’s because i’ve got a rigidbody on my player. How can I temporarily disable it?

  2. When the script is working it only goes up a small amount every time a key is pressed. I need it to be a smoother movement.

Here’s my code:

var target : Transform;

function Update () {
	
	if(Input.GetKeyDown("left shift")) {
	target.position += Vector3.up;
	}
}

General ideas on how to make the script better would be appreciated.

maybe you could use the plane script on it ? or modify it to the keys u want to use for it … its somewhere in the forums here that plane script …or just add more force to your script there ? example Vector3.up * 200
or so some other number

You want to be adding velocity, not teleporting upwards
(“.position =” is == teleporting)
And you want to be doing it constantly, not only once when you press the key

var boostFactor : float = 100; // or whatever

function Update () {

if ( Input.GetKey("left shift") ) {
 target.rigidbody.velocity += target.transform.up * boostFactor;
}

why don’t you just read the 3d person tutorial. there is a jetpack there

@Vicenti

Sorry but the script isn’t working, I’m not getting any errors but when I press the key nothing happens.

@ivkoni

I did look at that but in that it works as a higher jump. I want my player to stay in the air, sorry if that wasn’t clear.

You must have something else influencing the rigidbody’s velocity or position, or you’ve set the boostFactor too low.

i am finding the script from vicenti doesn’t work unless you remove the character controller :confused: but if i do that my moving around script wont work…

maybe you could use something like

transform.rigidbody.velocity = Vector3(0, 1, 0);
transform.rigidbody.useGravity = false;

and then when you reach max height, set y velocity to 0. then if you release the jetpack button, you apply gravity and stop with the velocity. you can set up a max y height, and then make it so it cant go any higher

You may also set the following: rigidbody.isKinematic = true; I think that you should look at the solution which ivkoni has suggested. You have to modify it to make it work the way you want it.

The character controller overrides physics movement already. You have to handle the character’s Y-axis velocity yourself inside the script that’s already handling movement.

That is, somewhere you have “.Move( amount )” (or maybe .SimpleMove)

with amount being a vector3. Keep track of a “local gravity” for the player and do something like

if ( jetpackOn ) 
  localGravity += jetpackAcceleration * Time.deltaTIme;
else
  localGravity -= 9.81 * Time.deltaTime;

charactercontroller.Move( Vector3( x, localGravity, z ) );