Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 LV9999_Majin · Mar 03 at 10:47 AM · movementangle

Problem with addforce angle or mouse input

So this is what I have so far

 Quaternion rotationr = Quaternion.Euler(30, 0, 0);
         Vector3 directionr = rotationr * transform.forward;
 
         Quaternion rotationl = Quaternion.Euler(-30, 0, 0);
         Vector3 directionl = rotationl * transform.forward;
 
         float mouseX = Input.GetAxis("Mouse X");
 
 
 
         if (mouseX > 0 && grnded == false)
         {
             player.AddForce(directionr * airturnmom * mouseX * Time.deltaTime);
         }
 
         if (mouseX < 0 && grnded == false)
         {
             player.AddForce(directionl * airturnmom * mouseX * Time.deltaTime);
         }

It mostly works and turning right in the air gives the right force, when I turn left though it gives the opposite of the right one though. I've tried a bunch of stuff and it definitely seems like something is set up wrong somehow.

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

2 Replies

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

Answer by Captain_Pineapple · Mar 03 at 03:54 PM

Hey there,

first up please try to keep your code clean and easy to maintain:

 float mouseX = Input.GetAxis("Mouse X");        
 Quaternion rot = Quaternion.Euler(30*Mathf.Sign(mouseX), 0, 0);
  Vector3 dir = rot * transform.forward;
  
  if (!grnded)
 {
       player.AddForce(dir * airturnmom * mouseX * Time.deltaTime);
 }

This code above does the same thing as your current code and each thing that you have to change if something should be changed can be done with 1 change exactly. If your code has the almost the exact line twice after each other then things are not right.


Apart from that it is kind of weird that the right turn is working as you turn the forward vector around the x-axis, not the y-axis. But given your info that it indeed does work then the only thing that probably causes this issue is the fact that you multiply your dir (formerly directionl) with the mouseX value. mouseX goes negative which turns the vector 180°.


So what you probably want to do here is "only" scale the vector as the rotation has already been done:

     player.AddForce(dir * airturnmom * Mathf.Abs(mouseX) * Time.deltaTime);
  

Let me know if that helped.

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

Answer by LV9999_Majin · Mar 03 at 08:41 PM

Wow yeah, that worked perfectly. Still like 100 other problems with the movement, that's doing what it's supposed though. Thanks a ton.

Also pretty sure there's no chance I'm keeping any code clean yet. I'm literally just trying to mangle random things in from the unity descriptions as I actually figure out what's going on.

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

193 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 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 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 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 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 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 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 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 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 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

How to rotate a character facing direction of movement like sonic the hedgehog 2 Answers

Move object towards an angle the distance of two points 1 Answer

More Efficient Way to Move Object at Angle 0 Answers

How to rotate Character depending on the inclination of the platform or its parts? 1 Answer

Bounce into the air 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