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 BTStone · May 20, 2012 at 03:25 PM · 2diosiphonejumpcharacter controller

[Character Controller] Jump-Movement in other direction while beeing in midair

Hey there,

so i managed to move my character with a character collider (via vectors and .SimpleMove) Everything works quite well, except the Jump. I am working on an iOS 2D Plattformer game, so i have four Buttons (Move Left, Move Right, Attack and Jump) The Jump-Button does it's job, but there is a little problem.

These are the four scenarios:

  • when i move to the left (pressing the MoveLeft-Button, the Character flips to the left) AND the Jump-Button it's jumping to the left and playing the Jump-Animation. Everything allright.

  • when i move to the right (pressing the MoveRight-Button, the Character flips to the right) AND the Jump-Button it's jumping to the right and playing the Jump-Animation. Everything allright.

  • when i jump (pressing the Jump-Button, the Character plays the Jump-Animation) AND the MoveLeft-Button it's moving in midair to the left and playing the Jump-Animation to the end. Everything allright.

  • when i jump (pressing the Jump-Button, the Character plays the Jump-Animation) AND the MoveRight-Button it's moving in midair to the right and playing the Jump-Animation to the end. Everything allright.

BUT:

when i press the MoveLeft-Button and then the Jump Button to get in midair AND then pressing the MoveRIGHT-Button the Character flips to the right but moves in the left direction. Same behaviour vice versa.

Here is an excerpt of my code:

 void moving ()
 {
     isButtonDown = false;

     
     foreach (Touch touch in Input.touches) {
         
         if (guiTexture.HitTest (touch.position)) {
             
             isButtonDown = true;
                     
                             
             if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled) {
                 
                 if (!lookRight) {
                     player.GetComponent<exSprite> ().HFlip ();
                     lookRight = true;
                     script2.lookLeft = false;
                 }
                 
                 if (script.inAir == true) {
                                             
                     direction = transform.TransformDirection (Vector3.right);
                     controller.SimpleMove (direction * speed);
                     
                     Debug.Log ("IN DER LUFT RECHTS!");
                 } else {
                     
                     script.inAir = false;
                     lookRight = true;
                     
                     direction = transform.TransformDirection (Vector3.right);
                     controller.SimpleMove (direction * speed);

                     
                     if (!player.GetComponent<exSpriteAnimation> ().IsPlaying ("RitterMove")) {
                         player.GetComponent<exSpriteAnimation> ().Play ("RitterMove");
                         playingAnim = true;
                 
                     }
                 }
             } else if (touch.phase == TouchPhase.Ended) {
                 
                 playingAnim = false;
                 
                 if (playingAnim == false) {
                     player.GetComponent<exSpriteAnimation> ().IsPlaying ("RitterMove");
                     player.GetComponent<exSpriteAnimation> ().Stop ();

                 }
                 
             }
         }
     }
             
 
 }    



That was the moving()-Method in the MoveRight-Script which is called in the Update()-Method, the MoveLeft-Script is pretty much the same, except the Vector3 goes to the left, not to the right.

Here is the jump-method:

 void LateUpdate ()
 {        
     direction.y -= gravity * Time.fixedDeltaTime;
     
     // Move the controller
     
     controller.Move(direction * Time.fixedDeltaTime); 
     
     if(controller.isGrounded)
     {
         inAir = false;
         canJump = true;
         Debug.Log("BIN AM BODEN!");
     }
     
 }
     
 void jumpAction ()
 {
     
 
     foreach (Touch touch in Input.touches) {
         
         if (controller.isGrounded) {
             canJump = true;
             inAir = false;
             
             if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled && guiTexture.HitTest (touch.position) && canJump == true) {
                 inAir = true;
                 canJump = false;

                 direction = new Vector2 (0, 0);
                 //direction = player.transform.TransformDirection (direction);
                 direction.y = jumpSpeed;


                 if(!player.GetComponent<exSpriteAnimation>().IsPlaying("RitterSprung"))
                 {
                     player.GetComponent<exSpriteAnimation>().SetDefaultSprite();
                 }
                                     
                 if (inAir) {
                     

                     
                     if (!player.GetComponent<exSpriteAnimation> ().IsPlaying ("RitterSprung")) {
                         player.GetComponent<exSpriteAnimation> ().Play ("RitterSprung");
                     }
                 }
                 
             } else if (touch.phase == TouchPhase.Ended) {
                 
                 if (player.GetComponent<exSpriteAnimation> ().IsPlaying ("RitterSprung"))
                     player.GetComponent<exSpriteAnimation> ().Stop ();
                 
                 if(controller.isGrounded)
                 {
                     player.GetComponent<exSpriteAnimation>().SetDefaultSprite();

                 }
             }
         } else {    
             inAir = true;
         }
     }
 }




Am i missing something? Is there a mistake somewhere? I appreciate any help :) (I'm sitting for hours in front of this problem...I

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

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Native iPhone Bluetooth Multiplayer? 1 Answer

Is unity the way to go for a 2D game for iOS? 2 Answers

why unity IPA file size increased after installation as compare to unity APK? 1 Answer

Does Unity take care of unseen objects? 2 Answers

What shader blending modes don't work on iOS? 1 Answer


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