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 pjmoradiya · Apr 19, 2017 at 10:02 AM · c#unity 5camerarotationturning

How can I turn the direction of bicycle in Unity?

Hi I am new to the Unity and I am making Bicycle project in my school. I am facing a problem regarding turning the bicycle. I am attaching the YouTube link for the video which I made in which you can see the problem. I am also copying the C# Script below. Please help me through this.

YouTube Video Link : https://youtu.be/Xbd4ejR_4cY

Thank You

C# Script:

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class player : MonoBehaviour { public Animator anim; public Rigidbody rbody; private bool run;

 private float inputH;
 private float inputV;

 void FixedUpdate(){
     Rotation ();
 }

 private float wantedYRotation;
 private float currentYRotation;
 private float rotateAmountByKeys = 2.5f;
 private float rotationYVelocity;
 void Rotation(){
     if (Input.GetKey(KeyCode.LeftArrow)) 
     {
         wantedYRotation -= rotateAmountByKeys;
     }
     if (Input.GetKey(KeyCode.RightArrow)) 
     {
         wantedYRotation += rotateAmountByKeys;
     }
     currentYRotation = Mathf.SmoothDamp (currentYRotation, wantedYRotation, ref rotationYVelocity, 0.25f);
 }


 // Use this for initialization
 void Start () 
 {
     anim = GetComponent<Animator>();
     rbody = GetComponent<Rigidbody> ();
     run = false;
 }
 
 // Update is called once per frame
 void Update () 
 {
     if (Input.GetKey (KeyCode.LeftShift)) {
         run = true;
     } 
     else 
     {
         run = false;
     }

     inputH = Input.GetAxis ("Horizontal");
     inputV = Input.GetAxis ("Vertical");

     anim.SetFloat("inputH", inputH);
     anim.SetFloat("inputV", inputV);
     anim.SetBool("run",run);

     float moveX = inputH*100f*Time.deltaTime;
     float moveZ = inputV*100f*Time.deltaTime;

     if (moveZ <= 0f) 
     {
         moveX = 0f;
     }  
     else if (run) 
     {
         moveX *= 2f;
         moveZ *= 2f;
     }

     rbody.velocity = new Vector3 (moveX, 0f, moveZ);
     
 }

}

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by jackishere · Apr 19, 2017 at 03:08 PM

have you applied the rotation?

 transform.rotation=Vector3.up*currentYRotation;
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 pjmoradiya · Apr 20, 2017 at 06:30 PM

Thank you for your response. I am new to the Unity so I exactly don't know how to use rotation in this script. Can you please give me some idea regarding this?

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 thaMorganic · Apr 20, 2017 at 08:04 AM

Hmm, not quite sure what you wanna do, but try this:-

 transform.rotation = Quaternion.Euler (X, Y, Z);

Note: Replace X,Y, Z with the rotation you want on every axis.

If you want to make it rotate continuously on a specific axis, use this:-

 Quaternion rot = Quaternion.Euler (0, rotationSpeed, 0);
 transform.rotation *= rot;

Note: Put rotationSpeed in the axis you wanna rotate, like this

X-axis > Quaternion.Euler (rotationSpeed, 0 , 0);

Y-axis > Quaternion.Euler (0, rotationSpeed, 0);

And so 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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

how do i make first person character rotate left and right along with camera? 0 Answers

Can't do Quaternion.AngleAxis twice. 1 Answer

Flip over an object (smooth transition) 3 Answers

Scripting Help(C#): Make object face a direction based on rotation of another 1 Answer

How to move camera up and down 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