![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | xdanic |
Hi, I was trying to convert some code I did in unity into GDScript and it seemed quite straightforward, until I tried to do this, and apparently, Quat doesn’t return a Vector 3, but I don’t know how to convert it into one…
-This is what the C# code in unity looks like for reference-
public class ThirdPersonCamera : MonoBehaviour
{
public Vector3 offset;
private Transform target;
[Range (0, 1)] public float lerpValue;
public float sensibilidad;
void Start()
{
target = GameObject.Find("Player").transform;
}
void LateUpdate()
{
transform.position = Vector3.Lerp(transform.position, target.position + offset, lerpValue);
offset = Quaternion.AngleAxis(Input.GetAxis("Mouse Y") * sensibilidad, -Vector3.right) * offset;
offset = Quaternion.AngleAxis(Input.GetAxis("Mouse X") * sensibilidad, Vector3.up) * offset;
Debug.Log(offset);
transform.LookAt(target);
}
}
And this is what I’m trying to do on godot
extends Camera
var target
export var offset = Vector3(0, 3, -8)
export var lerp_val = 0.2
export var sens = 5
# Called when the node enters the scene tree for the first time.
func _ready():
target = get_node("../Player")
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
global_transform.origin = Vector3(lerp(global_transform.origin, target.global_transform.origin + offset, lerp_val))
offset = Quat.IDENTITY.set_axis_angle(Vector3.UP, Input.get_action_strength("mousey"))
offset = Quat.IDENTITY.set_axis_angle(-Vector3.RIGHT, Input.get_action_strength("mousex"))
look_at(target.transform.origin, Vector3.UP)