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 : - YouTube
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);
}
}