C
C#15mo ago
VoidStars

❔ im dumb and stupid

just started learning C#, like, today. im making an FPS in Unity and started with movement/camera controls. it had been going well, until i ran into trying to clamp the Y-axis movement of the player cam. here's my code, the goal is to make the camera lock into place when it either hits 360 or 180, then change the rotation of the camera to be back within the 0-179 range, so that the player cant spin the camera 360. the locking-in-place works well, but i cant get it to revert back to the acceptable 0-180 range so the player can move the camera again. expect very huge, glaring mistakes and absolutely ZERO optimization. ----------------------------------------------------------------------------------------- mouseY = viewCam.localRotation.eulerAngles.y; if (mouseY <= 179) { viewCam.localRotation = Quaternion.Euler(viewCam.localRotation.eulerAngles + new Vector3(0, mouseInput.y, 0)); } else if (mouseY == 360) { mouseY == 0;
} else if (mouseY == 180) { mouseY == 179;
}
8 Replies
mg
mg15mo ago
i dont use unity and cant help you but that's a really dumb thing to title your question
Angius
Angius15mo ago
If you just started learning C#... I'd advise to learn C#, not jump straight into making the second coming of Overwatch with Unity
mg
mg15mo ago
people don't want to help people who don't believe in their own capabilities
Iron
Iron15mo ago
You're comparing the value of mouseY with 360 and 180 using the "==" operator which is a comparison operator. Instead, you should use the assignment operator "=" to assign the value of 0 to mouseY when mouseY is equal to 360 and assign the value of 179 to mouseY when mouseY is equal to 180
VoidStars
VoidStarsOP15mo ago
thanks
Iron
Iron15mo ago
Np, try it tho im also not an expert but i think thats the issue. If you like game dev unity is a good way to learn c# have fun 🙂
Florian Voß
Florian Voß15mo ago
I suggest to go a few steps back when you have just started with c# basics you shouldn't be diving into gamedev already get a good grasp of the fundamentals before you start a project of any kind, especially when we're talking gamedev with Unity
Accord
Accord15mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server