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 Poseidon1145 · Sep 17, 2017 at 01:17 AM · rotationjoystick

stay the rotation in character

Hi i have a problem, I create a script that when using the input of a joystick, where it pointed the joystick rotated the character and when you stop moving the joystick your rotation returned to 0

but I need to move the joystick and rotate the character to stop moving the joystick does not return to zero but is in its last rotation.

for example I moved the character to a rotation of 30 degrees and when releasing the joystick that is not returned to 0 but stays in 30

sorry for my english i used the Google Translate xD

alt text

wtf.png (8.1 kB)
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
0

Answer by unit_nick · Sep 17, 2017 at 03:17 AM

 /*
  * To see this work just create a new project
  * and attach this script to an empty game object 
  */
 
 using UnityEngine;
 
 public class Setup : MonoBehaviour {
 
     GameObject player;
 
     public float horizontalSpeed = 1;
     public float verticalSpeed = 1;
     public bool returnRotation = false;
 
     private float horizontal = 0;
 
     private void Start()
     {
         GameObject plane = GameObject.CreatePrimitive(PrimitiveType.Plane);
         plane.name = "Plane";
         plane.GetComponent<Renderer>().material.color = Color.black;
 
         player = GameObject.CreatePrimitive(PrimitiveType.Capsule);
         player.name = "Player";
         player.transform.position += Vector3.back * 4f;    
         player.AddComponent<Rigidbody>().useGravity = true;
         player.GetComponent<Rigidbody>().constraints = (RigidbodyConstraints)122;
 
         GameObject visor = GameObject.CreatePrimitive(PrimitiveType.Cube);
         visor.name = "Visor";
         visor.transform.parent = player.transform;
         visor.transform.localPosition = new Vector3(0f, 0.5f, 0.24f);
         visor.transform.localScale = new Vector3(0.95f, 0.25f, 0.5f);
         visor.GetComponent<Renderer>().material.color = Color.black;
     }
 
     private void Update()
     {
         float horizontalImpulse = Input.GetAxis("Horizontal");
 
         if (horizontalImpulse > 0f)
         {
             horizontal += horizontalSpeed * Time.deltaTime * 100;
         }
         else if (horizontalImpulse < 0f)
         {
             horizontal -= horizontalSpeed * Time.deltaTime * 100;
         }
         else if (returnRotation)
         {
             float absValue = Mathf.Min(Mathf.Abs(horizontal), Mathf.Abs(horizontalSpeed * Time.deltaTime * 100));
             horizontal -= absValue * Mathf.Sign(horizontal);
         }
 
         player.transform.localRotation = Quaternion.Euler(0, horizontal, 0);
 
         player.transform.position += player.transform.forward * Input.GetAxis("Vertical") * verticalSpeed * Time.deltaTime;
     }
 }
 
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

96 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

Related Questions

How to control a 2d character in an top-down android game with the standard joystick? 1 Answer

Rotate a GameObject in the Vector3 direction? 1 Answer

How to smoothly rotate object in direction of analog joystick? 1 Answer

Joystick for WASD & Joystick for Camera? 0 Answers

Rotate with joystick - LookAt axis flipping 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