Hi guys, it's Friday!!! i need to apply a jetpack-style vertical force to my spaceship. The problem is I need it to be applied for as long as the shift key is held IN and not like a jump, for only one frame. I can't figure this out...
I got this to work with: Code (csharp): if (Input.GetKeyDown("left shift")) { constantForce.force = Vector3.up * 8000; } if (Input.GetKeyUp("left shift")) { constantForce.force = Vector3.up * 0; } Please, if someone have a better way, maybe better performance, please let us know.[/code]
Use GetKey instead of GetKeyDown/Up. http://unity3d.com/support/documentation/ScriptReference/Input.html
Vicenti: Depends on how he plans to implement. The way he's set it up works fine. Using GetKey (with ConstantForce) would still require two conditionals, one to set the ConstantForce, and another to set it back to 0.
But there would only be one check. Slightly faster. Code (csharp): if ( Input.GetKey("left shift") ) constantForce.force = 8000 * Vector3.up; else constantForce.force = Vector3.zero;
Thanks guys and btw, I'm retarted lol. my heading was suppose to read it's ALMOST Friday!!! Thanks again
I put that script on my first person shooter and it gave me this error "MissingComponentException: There is no 'ConstantForce' attached to the "FirstPerson Player" game object, but a script is trying to access it. You probably need to add a ConstantForce to the game object "FirstPerson Player". Or your script needs to check if the component is attached before using it. jet pack 2.Main () (at Assets\jet pack 2.js:4)" Any ideas? Thanks!
In the editor add the ConstantForce component to your game object (Component > Physics > ConstantForce)
I've tried all steps mentioned but the worm player i have is still not flying upwards: this is my first code, what am i missing? ANSWER: i didnt uncheck kinematic, and the character controller component overrides the constant force physics