- Home /
Making a Jetpack
I am trying to make is so that my player has like a jet boost to push him up in the air when you press the Left Shift key.
I have tried all the following codes for no results.
This One
 if ( Input.GetKey("v") )
  constantForce.force = 8000 * Vector3.up;
 else 
  constantForce.force = Vector3.zero;
This One:
 var boostFactor : float = 100; // or whatever
  
 function Update () {
  
 if ( Input.GetKey("left shift") ) {
  target.rigidbody.velocity += target.transform.up * boostFactor;
 }
This One:
 if ( jetpackOn ) 
  localGravity += jetpackAcceleration * Time.deltaTIme;
 else
   localGravity -= 9.81 * Time.deltaTime;
  
 charactercontroller.Move( Vector3( x, localGravity, z ) );
None of these even make my character leave the ground. I have just the starndard character controller on it using the thirdperson controller and i have added a ridgidbody.
A jetpack; you mean like- the one Lerpz has in the first tutorial? Just sayin'...
Answer by programmrzinc · Oct 05, 2012 at 05:32 PM
Use this code Instead
 var speed : float = 6.0;
 var jumpSpeed : float = 8.0;
 var gravity : float = 20.0;
 
 private var moveDirection : Vector3 = Vector3.zero;
 
 function Update() {
     var controller : CharacterController = GetComponent(CharacterController);
     if (controller.isGrounded) {
         // We are grounded, so recalculate
         // move direction directly from axes
         moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,
                                 Input.GetAxis("Vertical"));
         moveDirection = transform.TransformDirection(moveDirection);
         moveDirection *= speed;
         
         if (Input.GetButton (KeyCode.V)) {
             moveDirection.y = jumpSpeed;
         }
     }
 
     // Apply gravity
     moveDirection.y -= gravity * Time.deltaTime;
     
     // Move the controller
     controller.Move(moveDirection * Time.deltaTime);
 }
what is character controller? component wise is it something I need to make like a player? or is this how I enter the script? new to this sorry
Answer by slkjdfv · Oct 05, 2012 at 05:29 PM
Does your character have a rigidbody attached? you can't add forces to an object unless said object has a rigidbody attached. And IF it does have a rigid body attached make sure isKinimatic is unchecked. After all that try using rigidbody.addforce.
Answer by Mander · Oct 05, 2012 at 05:34 PM
ok here. look using the character controller. u may use a very useful script from the documentation.
here u can find how to "Jump" but u can modify it to ur convenience. give it a try.
Your answer
 
 
             Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Converting to C# 1 Answer
Convert js to c# 2 Answers
Why does my slide out menu not work when i translate from JS to C#? 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                