Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

I have a problem says "cannot convert from 'UnityEngine.Quaternion to 'UnityEngine.Vector3' "

Discussion in 'Scripting' started by boracebi, Jun 25, 2019.

  1. boracebi

    boracebi

    Joined:
    Jun 25, 2019
    Posts:
    2
    code here

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class PlayerMovement : MonoBehaviour
    7. {
    8.     public float turnSpeed = 20f;
    9.  
    10.     Animator m_Animator;
    11.     Rigidbody m_Rigidbody;
    12.     Vector3 m_Movement;
    13.     Quaternion m_Rotation = Quaternion.identity;
    14.  
    15.     void Start ()
    16.     {
    17.         m_Animator = GetComponent<Animator> ();
    18.         m_Rigidbody = GetComponent<Rigidbody> ();
    19.     }
    20.  
    21.     void FixedUpdate ()
    22.     {
    23.         float horizontal = Input.GetAxis ("Horizontal");
    24.         float vertical = Input.GetAxis ("Vertical");
    25.        
    26.         m_Movement.Set(horizontal, 0f, vertical);
    27.         m_Movement.Normalize ();
    28.  
    29.         bool hasHorizontalInput = !Mathf.Approximately (horizontal, 0f);
    30.         bool hasVerticalInput = !Mathf.Approximately (vertical, 0f);
    31.         bool isWalking = hasHorizontalInput || hasVerticalInput;
    32.         m_Animator.SetBool ("IsWalking", isWalking);
    33.  
    34.         Vector3 desiredForward = Vector3.RotateTowards (transform.forward, m_Movement, turnSpeed * Time.deltaTime, 0f);
    35.         m_Rotation = Quaternion.LookRotation (desiredForward);
    36.     }
    37.  
    38.     void OnAnimatorMove ()
    39.     {
    40.         m_Rigidbody.MovePosition (m_Rigidbody.position + m_Movement * m_Animator.deltaPosition.magnitude);
    41.         m_Rigidbody.MoveRotation (m_Rotation);
    42.     }
    43. }
    44.  
    45.  
     
  2. Boz0r

    Boz0r

    Joined:
    Feb 27, 2014
    Posts:
    419
    You haven't stated which line gives you the error, but you can get a vector with the quaternion's euler angles from its eulerAngles property.
     
  3. boracebi

    boracebi

    Joined:
    Jun 25, 2019
    Posts:
    2
    its 44th column
     
  4. ??? Line? that is empty. If column then which line? Are you sure the error is in this file?

    Also do not use voting here, no need for it. And it's not fun.