• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by user-12161 (google) · Apr 28, 2011 at 08:36 PM · javascriptjetpack

jetPack key lock.

I'm trying to make a jetpack game and so far everything is going greate. until i reached a problem while making the jetpack code. when ever the character is in the air he can only rotate but cannot move forward or backward plus my if the character gets too high he just goes into an endless bounce ignoring all keys except for the rotation keys. I'm using moveDirection.y to lift the player. this is my entire player.js script please help is you can.

var speed : float = 15.0; var jump : float = 10.0; var gravity : float = 20.0; var fuel : float = 100.0; var torque : float = 0.2;

var spawn : Transform; var fire : Transform; var ext : Transform;

private var nextBoost : float = 0.0; private var exel : float = 0.0; private var grounded : boolean = false; private var moveDirection = Vector3.zero;

function FixedUpdate() { var controller : CharacterController = GetComponent(CharacterController); transform.Rotate(0, Input.GetAxis ("Horizontal") * speed/3, 0);

 var forward = transform.TransformDirection(Vector3.forward);
 var curSpeed = speed * Input.GetAxis ("Vertical");
 controller.SimpleMove(forward * curSpeed);

 if(Input.GetButton("Jump")){  
     moveDirection.y = jump;
 }
 if(Input.GetButton("Fire1")){
     if(fuel>0){
         Instantiate(fire, ext.position, ext.rotation);
         if(Time.time > nextBoost){
             nextBoost = Time.time + torque;
             exel++;
             fuel--;
         }
     }else{
         exel=0;
     }
 }else{
     if(exel>0){
         exel--;
     }
 }

 moveDirection.y += exel;

 moveDirection.y -= gravity * Time.deltaTime;
 var flags = controller.Move(moveDirection * Time.deltaTime);
 grounded = (flags & CollisionFlags.CollidedBelow) != 0;

}

function OnControllerColliderHit(hit : ControllerColliderHit) { if(hit.gameObject.tag=="catcher") { transform.position = spawn.position; } }

@script RequireComponent(CharacterController)

thanks. :)

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by sneftel · Apr 28, 2011 at 09:06 PM

Calling Move() and/or SimpleMove() more than once per frame causes weird results. I suggest that you scale forward*curSpeed by deltaTime and add it into your call to Move() instead of applying it separately.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image user-12161 (google) · Apr 29, 2011 at 08:17 AM 0
Share

thanks that help a little to the lifting. but i still can't move while i'm in the air.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Sequence of function Calls 2 Answers

Faux Gravity Prolem? #2 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges