0 votes

I am attempting to write an orbit control (basically, get the camera in my game to behave the same way the godot viewport does). I am doing this to familiarize myself with the godot transforms.

So far I have the positioning of my camera working. However, when I try to point it at the center of orbit (0,0,0), the LookingAt function fails to work. Printing out (The C# debugger isn't working *cry*) the values show no change occurs as a result of this function. This is despite the fact that the camera is moved around. I tried various values for the up-axis, no change witnessed.

Here are the pertinent functions from my Camera node's script:

private Vector2 rotateStart;
private Vector2 rotateEnd;
private Spherical spherical = new Spherical();
private Vector3 target = new Vector3();

public void HandleRotation(float delta)
    //Current cursor location
    rotateEnd = GetViewport().GetMousePosition();
    //Get change since last time
    Vector2 RotateDelta = rotateEnd - rotateStart;
    //Get the transform...
    var transform = GetGlobalTransform();
    //Set the spherical to the current location
    //Get viewport size
    var viewportSize = GetViewport().GetVisibleRect().Size;
    //Calculate changes to equatorial and vertical rotations.
    spherical.theta += 2 * (float)Math.PI * RotateDelta.x / viewportSize.x;
    spherical.phi += 2 * (float)Math.PI * RotateDelta.y / viewportSize.y;
    //Vector to store the final transform
    var final_transform = new Vector3();
    //Copy spherical cordinates to position vector.
    spherical.CopyToVector3(ref final_transform);
    //Apply position change to object transform.
    transform.Translated(final_transform - transform.origin);
    //Print transform
    //Point at origin (point of orbit)
    transform.LookingAt(target, new Vector3(0, 1, 0));
    //Print transform, outputs not chang during tests.
    //LookAt(target, new Vector3(0, 1, 0))
    //Apply the transform
    //Save last position.
    rotateStart = rotateEnd;

public override void _Process(float delta)
    // Called every frame. Delta is time since last frame.
    // Update game logic here.
    if (Input.IsMouseButtonPressed((int)ButtonList.Middle))
        //Todo, move this to input event
        rotateStart = GetViewport().GetMousePosition();
in Engine by (12 points)
edited by

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.