+1 vote

tried this line:

scopepiv.RotationDegrees.y = Mathf.Clamp(scopepiv.RotationDegrees.y, -100.0f, 100.0f);

but it says that I can't modify the return value of Spatial.RotationDegrees.y because it is not a variable.

how are you supposed to modify the x/y value of a vector3 property in c#???

in Engine by (35 points)

1 Answer

+3 votes
Best answer

It's one of the main drawbacks of C#, the structs (x, y, z) have to be set to a Vector3 variable instead of being changed directly.

Vector3 rotation;

void YourFunction()
{
    rotation.x = //value;
    rotation.y = //value;
    scopepiv.SetRotationDegrees(rotation);
}
by (3,219 points)
selected by

thanks for answering and clarifying, I fixed my code not long before you answered.
I guess there is no better way to do it.

here it is:

    Vector3 rotDeg = scopePiv.RotationDegrees;
    rotDeg.y = Mathf.Clamp(rotDeg.y, -100.0f, 100.0f);
    rotDeg.x = Mathf.Clamp(rotDeg.x, -40.0f, 40.0f);
    scopePiv.RotationDegrees = rotDeg;
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.