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 midnightcoder · Mar 22, 2012 at 05:53 PM · c#transformjumpingx-axis

how can i change the x position while jumping on air using c#?

have a character controller which jumps but while jumping i want to change the x position of the character so basically he can turn while jumping, this is my attempt so far

     //start of character controller
     CharacterController controller = GetComponent<CharacterController>();
     if (controller.isGrounded) {
 
      //get the player vector movement vector
          movePlayer = new Vector3(Input.acceleration.x,0,1);
          //float h = Input.acceleration.x;
          //translate the players movement
          transform.Translate(movePlayer * moveSpeed * Time.deltaTime);
          //the run animation
          animation.CrossFade("run");
 
     if (Input.GetButton("Jump")){
     //my problem is here, the x axis on the vector3 is not happening    
     movePlayer =transform.TransformDirection(new   Vector3(Input.acceleration.x,jumpSpeed,forwardJumpSpeed)); 
 
 
               }  
 
          }
 
     // attach the gravity and move controller     
     movePlayer.y -= gravity * Time.deltaTime;
     controller.Move(movePlayer * Time.deltaTime);

my problem here is commented in the code.

Comment
Add comment · Show 2
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 midnightcoder · Mar 22, 2012 at 06:09 PM 0
Share

by the way code works fine, its just in the jump section on the transform.TransformDirection(x is not working,y is good, z is good) :((

avatar image midnightcoder · Mar 22, 2012 at 06:41 PM 0
Share

its funny because when i put a float like this it works, it changes the direction

 if (Input.GetButton("Jump")){
        
     movePlayer =transform.TransformDirection(new   Vector3(2.5f,jumpSpeed,forwardJump)); 
 
 } 

but when i put this:

 if (Input.GetButton("Jump")){
     //my problem is here, the x axis on the vector3 is not happening    
     movePlayer =transform.TransformDirection(new   Vector3(Input.acceleration.x,jumpSpeed,forwardJumpSpeed)); 
 
 
               } 

 

it deosnt work, its so wierd, i think thier is a bug in unity, is thier an email i can contact.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Mar 22, 2012 at 07:40 PM

I'm just wondering. Input.acceleration returns the realworld acceleration of a mobile device (iPhone). Are you sure that's what you're after?

Usually you would use something like Input.GetAxis ("Horizontal")

Comment
Add comment · Show 2 · 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 midnightcoder · Mar 23, 2012 at 08:06 AM 0
Share

i tried both of them, they both don't work!!! :(( thanks hough

avatar image Bunny83 · Mar 23, 2012 at 10:20 AM 0
Share

Ehmm, i actually asked (indirectly) for clarification. Do you want to develop for iPhone / Android or Standalone (Win / $$anonymous$$ac) or Webplayer?

Have you tried usng Debug.Log() to print out the values to see what is happening? We can't do this for you, we don't have your project.

Another thing is it seems you move your character two times. A charactercontroller is not a physic object. It should only be moved via the .$$anonymous$$ove() function. transform.Translate bypasses the collision detection.

btw just read it again. You said you want the player "can turn while jumping". You only move your player sideways, you never turn it or was that the expected behaviour?

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

a better movement code C# 3 Answers

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Implement the equation as a code? 1 Answer

Manipulating booleans from parent to child (C#) 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