Hi i’m trying to make a jetpack for my character and i’ve come across two problems.
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?
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;
}
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