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 Kachupi · Jan 12, 2014 at 11:01 PM · javascriptcharactercontrolleraxisturning

character turning problem!

ok so i've been following this tutorial to make my own character controller for my character http://www.youtube.com/watch?v=7hXSbA4sr-Q and so far it's been working fine up untill 29 mins in when he pastes a chunk of coding for making the character turn left right and back when it moves. The original coordinates didn't quite work for my character so i made a few edits to the code and this is what i have so far,

   function LateUpdate(){
 
 if(Input.GetAxis("Vertical") == 0){
 if(Input.GetAxis("Horizontal") > 0){
 body.localEulerAngles.y = 90;
 }else if(Input.GetAxis("Horizontal") < 0){
 body.localEulerAngles.y = -90;
 }
 }else if(Input.GetAxis("Vertical") > 0){
 if(Input.GetAxis("Horizontal") > 0){
 body.localEulerAngles.y = 45;
 }else if(Input.GetAxis("Horizontal") < 0){
 body.localEulerAngles.y = 135;
 }
 }else if(Input.GetAxis("Vertical") < 0){
 if(Input.GetAxis("Horizontal") > 0){
 body.localEulerAngles.y = -45;
 }else if(Input.GetAxis("Horizontal") < 0){
 body.localEulerAngles.y = -135;
 
 }
 }
 } 

the character will turn right, up and diaganal right/up aka all the positive positions are fine except right/down but its getting it to turn negatively eg left and down and so on thats the issue it just won't it only slides when i press those keys :/ i thought the negative code would be laid out the same as the possitive just all the values and numbers would be opposite and negative but apparently its not that simple >.< anyone have any ideas or could you fix my code for me and explain what i am doing wrong would be much apreciated :) x

Comment
Add comment · Show 8
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 getyour411 · Jan 14, 2014 at 12:01 AM 0
Share

Please update this post by highlighting your code and pressing the 10101/code button

avatar image robertbu · Jan 14, 2014 at 12:04 AM 0
Share

I formatted your code, but without proper indentation, it is difficult to read. I recommend you fix the indentation and repost your code. It may very well be that the issue is in the structure of your 'if' and 'else' statements. If so, proper indentation will likely highlight the problem.

avatar image Quillicit · Jan 14, 2014 at 08:15 AM 1
Share

The else if statement at line 15 will never be evaluated, as any time "Vertical" == 0 the compiler will not progress beyond the if group at lines 3-9.

At line 7 you'd want what you have at line 17. Line 12 should have a less-than symbol. Line 22 should have a greater-than symbol. Remove lines 15-20.

Hope that helps!

avatar image Kachupi · Jan 14, 2014 at 04:57 PM 0
Share

@Quillicit that has almost fixed my problem thanks :) it still cannot face down though how ever it now goes left and diagonally left/down, but right/down and left/up seem to be opposite to each other eg if i press the up arrow key and the left arrow key the character faces right/down whilst moving up/left and vice versa >.< i'm very new to JavaScript so i'm not great at this i am affraid but i have updated my code on this post with what you have given me so far, also sorry for those that couldnt read this and thanks to @robertbu for laying it out correctly i am new to unity and didn't realise it would look as horrid as it did when i posted but i went to bed shortly after so didnt have to time to tidy it lol x

avatar image Quillicit · Jan 15, 2014 at 12:46 AM 0
Share

You can't face down because you have no state for when you're not pressing a horizontal button. Between lines 9 and 10, try:

 body.localEulerAngles.x = 35;

And between 15 and 16:

 body.localEulerAngles.x = -35;

I'm not really sure why the tutorial has you using localEulerAngles, honestly. A better bet is transform.Rotate(x, y, z). You'll also want to get a $$anonymous$$athf.Clamp in the action too, to limit the up and down rotation.

Show more comments

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

20 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

character controller wont rise when I Jump :( 1 Answer

getting out of a vehicle 2 Answers

Fixing the NullReferenceException. 3 Answers

JavaScript Syntax and Punctuation Meanings Question 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 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