Hey y’all. So a while back I wrote a method that could handle camera movement properly along an isometric plane (as in, moving the camera up moves it forward the way you think it would, not along the actual xyz axes). I remember it took me like a whole day of frankensteining tips from other people online to figure out how to do it without the y axis moving. It’s working fine and I should never ever touch it again, but I noticed today that when I drag the mouse up (i.e. when I move the camera forward) I noticed it’s a little less sensitive than when I drag left or right. Problem is I don’t know where in the code I could put a yDragSensitivityvariable to fix it.
Here’s the method:
void Drag() {
if (Input.GetMouseButton(1)) // right mouse button for drag
{
// calculate the movement vector based on camera orientation, how did I come up with this?
Vector3 forwardDirection = transform.forward;
Vector3 rightDirection = Quaternion.Euler(0, 90, 0) * forwardDirection; // literally why did I do this? I mean, it's working ...
Vector3 movement = (rightDirection * -mouseX + forwardDirection * -mouseY) * dragSpeed * Time.deltaTime;
movement.y = 0f; // set the movement in y axis to 0 to keep the camera height fixed
// apply movement to the camera
// transform.position += movement;
Vector3 targetPosition = transform.position + movement;
transform.position = Vector3.Lerp(transform.position, targetPosition, 0.5f);
}
}
}
Now, I’ll admit it’s really not that noticeable, but as a perfectionist if I don’t fix this my soul will be tormented for all eternity.
Just multiply the “forwardDirection” by a number (greater than 1, obviously). If you want to make it “variable”, go ahead. It’s good practice if you name it descriptively.
Otherwise, if you insist on doing it yourself, when I read this:
The first thing i think is perhaps you are scaling the camera movement to the raw mouse movement and not taking into account camera angle? If your camera is isometric, this is exactly the result you would get, as one axis is effectively scaled to screen coordinates at a different rate than the other axis, based on the angle of viewing.
Technically in a 3D space this would be accurate but what you are noticing is due to the fact that the horizontal movement is more-or-less 1:1 with the distance in space on the screen but when moving the mouse vertically you are traveling through the depth of the space so foreshortening causes less apparent vertical movement. I had a similar issue with one of my own games where I used a weird perspective camera to make things appear to be a 2D scene that you’d typically see in older games that were faking a 3D view using isometric graphics (sounds weird I know. I have a tendency to makes technology in my games that mimcs old fashioned techniques that were used due to limits of hardware. But I end up having to fake them because I’m actually using 3D lol)
Anyway, I’d probably just multiply the scaler it with the mouseY value you assign to the ‘movement’ vector.
So for example rightDirection * -mouseX + forwardDirection * -mouseY)
Becomes rightDirection * -mouseX + forwardDirection * -mouseY * yDragSensitivityvariable)
Also, a good idea. It might be overkill in this case, but now I use Cinemachine in every Unity project I start. It takes a little time to learn what all of the settings do, though,
This is why I love this community — look at all these great answers. You’re real OGs for pulling through.
It was right in front of me and I didn’t notice it. Thanks, guys, that was exactly it. I guess the __rightDirection = Quaternion.Euler(0, 90, 0) * forwardDirection__ line was throwing me off, I think the reason why I used that and not **transform.right** was because since the camera rotates, I thought transform.right wouldn’t work properly. It does. That one line made my BrainController.cs question all the other lines.
…
Don’t laugh at me, but I completely forgot Cinemachine exists . My current messy CameraController.cs works (for now), so I won’t mess with it, but I’ll be sure to remember that Cinemachine is a thing next time.
Anyway, thank you so much guys! Be sure to be on the lookout for my next dumb question.