Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 NoChillNaz · Aug 19, 2017 at 08:05 PM · charactercontrollercharacter movementcharacter controllingcharacter.move

Player Controller "Horizontal" input convert to "left" and "right"

I am currently creating a game in which the player can drive around on a spherical planet. I wrote the code below with original intentions of publishing it on a pc platform but I decided to convert it over to mobile. What I would like to do is convert what is in the fixed update into two separate voids: a left control and a right control (idk if that makes sense). I guess what I am trying to say is how would I convert

rotation = Input.GetAxisRaw("Horizontal");

into a left and right void? Thanks

 public float rotateInBetween = 4f;
 public float rotateAdd = 25f;
 public float moveSpeed = 5f;
 public float rotationSpeed = 200f;
 public float accelerationAddSpeed = 0f;
 public float accelerationInBetween = 0f;
 public float slowMotionLength = 3f;
 public float animationSlow = .2f;

 private float rotation;
 private Rigidbody rb;

 void Start()
 {
     rb = GetComponent<Rigidbody>();
     StartCoroutine(rotateSpeedAdd());
 }

 void Update()
 {
     if (Input.GetButtonDown("Fire1"))
     {
         StartCoroutine(timeSlowPowerUp());
     }

     rotation = Input.GetAxisRaw("Horizontal");
     rotateSpeedAdd();
 }


 void FixedUpdate()
 {
     rb.MovePosition(rb.position + transform.forward * moveSpeed * Time.fixedDeltaTime);
     Vector3 yRotation = Vector3.up * rotation * rotationSpeed * Time.fixedDeltaTime;
     Quaternion deltaRotation = Quaternion.Euler(yRotation);
     Quaternion targetRotation = rb.rotation * deltaRotation;
     rb.MoveRotation(Quaternion.Slerp(rb.rotation, targetRotation, 50f * Time.deltaTime));
     //transform.Rotate(0f, rotation * rotationSpeed * Time.fixedDeltaTime, 0f, Space.Self);
 }
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

1 Reply

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

Answer by bramieboy100 · Aug 19, 2017 at 09:31 PM

I don't know if you want to check for other input rather than the horizontal axis but you could check in the fixed update if the Input.GetAxisRaw("Horizontal") is greater than zero or below zero. One of them is left and one of them is right.

So something like:

 void FixedUpdate (){
  if (Input.GetAxisRaw("Horizontal") > 0) {
   //Left??
  }
  if (Input.GetAxisRaw("Horizontal") < 0) {
   //right??
  }
 }
Comment
Add comment · Show 1 · 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 NoChillNaz · Aug 19, 2017 at 09:56 PM 0
Share

When I read this I totally facepalmed. How did I not think of this lol. Thanks so much!

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

78 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

Related Questions

How to make character to face in specific direction.,How To Rotate Character When Arrow Key Is Pressed? 0 Answers

Smooth walljumping 0 Answers

Character Creeping Backwards 0 Answers

How do i prevent my Player from sliding when i stop walking? 1 Answer

Navmash Pushes Character Controller upwards (0.08, skin width) 0 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