0 votes

Been trying to create a basic orbit camera. So far I've managed to get the mouse motion event to turn a camera Gimbal node. Works fine for Horizontal rotations.

However, I can't seem to figure out how I can limit the Vertical Rotations. Ideally I want to limit the rotations between 1 and 89, as not to rotate over the top of the orbit pivot point.

extends Spatial

func _ready():

func _input(ev):
    if (ev.is_class("InputEventMouseMotion")):
        if (ev.button_mask&(BUTTON_MASK_LEFT)):

            var speed = ev.get_relative()



So I've tried clamping the rotation of the InnerGimbal, however when rotate_x is called it just ignores the clamp. So I'm not sure what to do.

in Engine by (48 points)

if im not mistaken you need to clamp the final result, that way you wont be able to go above or below the limits, instead of clamping the speed of the rotation, thus making it possible(yet may take more time) to exceed the limitations.

Yea I was thinking along those lines, however I can't see how I can do that, where should I clamp the values between 1 and 89?

instead of



var rotation = get_rotation
rotation.y = clamp(rotation.y + speed.x, Min, Max)

assuming they are all the correct functions and you are using Godot 2.1 branch...

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.