Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

How to change the Axis direction of the character

Discussion in 'Physics' started by simiji, Sep 8, 2020.

  1. simiji

    simiji

    Joined:
    Sep 21, 2017
    Posts:
    8
    ok let me explain, I created a scene with a camera which rotates 360 ° around the character. The problem is that when I change my angle of view, the character keeps the same controls, so the left and right are reversed as soon as the camera is rotated. I am not really trying to change the axes but to change the controls of the characters so that, whatever the angle of view, it is possible to control the character normally.

    Do you have any idea how to do this?

    Here is the script for the camera
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class ChangeAngle : MonoBehaviour
    6. {
    7.     float speed = 0.5f;
    8.     void Update()
    9.     {
    10.  
    11.      if( Input.GetKeyDown(KeyCode.D) )
    12.      {
    13.        StartCoroutine( Rotate(Vector3.up, 90, speed) );
    14.          }
    15.      if( Input.GetKeyDown(KeyCode.Q) )
    16.      {
    17.        StartCoroutine( Rotate(Vector3.up, -90, speed) );
    18.          }
    19.        }
    20.    IEnumerator Rotate( Vector3 axis, float angle, float duration = 0.1f)
    21.    {
    22.      Quaternion from = transform.rotation;
    23.      Quaternion to = transform.rotation;
    24.      to *= Quaternion.Euler( axis * angle );
    25.    
    26.      float elapsed = 0.0f;
    27.      while( elapsed < duration )
    28.      {
    29.        transform.rotation = Quaternion.Slerp(from, to, elapsed / duration );
    30.        elapsed += Time.deltaTime;
    31.        yield return null;
    32.      }
    33.      transform.rotation = to;
    34.        }
    35.     }
    36.  
    37.        
    38.    
    39.  
    40.  
    Thank you in advance for your help :)

    ps: sorry for my english, I used Google Translation ^^ '
     
  2. simiji

    simiji

    Joined:
    Sep 21, 2017
    Posts:
    8
    I tried Look at() but that not really worked really well