Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 Alter · Jan 17, 2013 at 03:41 PM · jumpcontrolsmovements

Movement/Jump help

Heya guys, I'm working on a runner style games and I have the base controls down. I only need to stop the player from being able to move during the jump.

This is what I've gotten so far but have had little luck. :(

     void Update ()
     {
         bool grounded;
 
         if (state != State.Hit) 
         {
             // Amount to move
             float amtToMove = Input.GetAxisRaw ("Horizontal") * PlayerSpeed * Time.deltaTime;
             
             // Move the Player
             transform.Translate (Vector3.right * amtToMove);
         
             // Wrap
             if (transform.position.x <= -6f)
                 transform.position = new Vector3 (-6f, transform.position.y, transform.position.z);
             else if (transform.position.x >= 6f)
                 transform.position = new Vector3 (6f, transform.position.y, transform.position.z);
             
             if (transform.position.z <= -0f)
                 transform.position = new Vector3 (transform.position.x, transform.position.y, -0f);
             else if (transform.position.z >= 0f)
                 transform.position = new Vector3 (transform.position.x, transform.position.y, 0f);    
         }
         
         if (Physics.Raycast (transform.position, -transform.up, 2)) 
         {
             grounded = true;            
             //reset our jump count since we hit the ground //0 for double jump
             jumpCount = 1;    
             Instantiate (DustPrefab,spawnA.position, Quaternion.identity);                
         } 
         
         else 
         {
             grounded = false;
             float amtToMove = Input.GetAxisRaw ("Horizontal") * 0.1f * Time.deltaTime;        
         }
         
         
         if (Input.GetKeyDown ("space") && (grounded || jumpCount < 1)) 
         {
             state = State.Hit;
             rigidbody.AddForce (0, 10, 0);
             rigidbody.AddRelativeForce (transform.up * jumpForce, ForceMode.Impulse);
             Instantiate (JumpPrefab, transform.position, Quaternion.identity);
             state = State.Playing;
         }        
     }
Comment
Add comment · Show 3
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 Alter · Jan 17, 2013 at 03:43 PM 0
Share

Or even dull down the movement.. It's looks like the players hits an invisible wall mid air.

avatar image robertbu · Jan 17, 2013 at 04:28 PM 1
Share

Can't you do something like:

 // $$anonymous$$ove the Player
 if (grounded)
     transform.Translate (Vector3.right * amtTo$$anonymous$$ove);

avatar image Alter · Jan 17, 2013 at 05:03 PM 0
Share

I can't believe I missed that, thank you!

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by ryba · Jan 17, 2013 at 05:23 PM

Simple add CharacterController component to your player game object, and use Move method to deal with moveing, just like in this example: http://docs.unity3d.com/Documentation/ScriptReference/CharacterController.Move.html

Comment
Add comment · 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

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.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Slowing player speed when in air 1 Answer

Jumping while moving 1 Answer

C# let a character jump 2 Answers

Jump Further When Key Is Held Down 1 Answer

Mecanim tutorial issue with jump 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