- Home /
hy people, im a little noob in unity so can someone please tell me why my code isnt working? the idea is to rotate "cameraprincipal" but for some reason the object wont rotate more than one inch
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class movcamera : MonoBehaviour, IDragHandler
{
public float velocidade = 0;
public Transform cameraprincipal;
public void OnDrag(PointerEventData data)
{
cameraprincipal.localRotation = Quaternion.Euler(cameraprincipal.rotation.x, cameraprincipal.rotation.y + data.delta.normalized.x * velocidade, cameraprincipal.rotation.z);
}
}
Answer by HellsHand · Apr 28, 2021 at 02:17 PM
This section cameraprincipal.rotation.y + data.delta.normalized.x * velocidade
basically sets the Y rotation
to whatever velocidade
is set to. If I'm correct you wanna rotate an object based on mousepositions x coord
and control it's rotation speed with velocidade
. If that's the case try this:
cameraprincipal.localRotation = Quaternion.Euler(cameraprincipal.rotation.x, Input.mousePosition.x * velocidade, cameraprincipal.rotation.z);
i found an answer to the problem to kkkk i was using rotation istead of rotation.eulerangles in this same section "Quaternion.Euler(cameraprincipal.rotation.x, cameraprincipal.rotation.y + data.delta.normalized.x * velocidade, cameraprincipal.rotation.z);" for some reason it worked maybe because rotation works with quaternions x,y,z,w and the "Quaternion.Euler" thing asks for Euler rotations x,y,z thats my "hipotesis" kkkkk
Your answer
![](https://koobas.hobune.stream/wayback/20220613032954im_/https://answers.unity.com/themes/thub/images/avi.jpg)