I’m making a 3D game with an orthographic cam. The movement is modified to accomodate to the relative rotation of the camera (i.e pressing up makes you go up, not on the upper left or upper right corner).
I want to make my little spacehip tilt toward the movement direction (this vector is diplayed by a red ray in the gif).
My first attempts were not successfull and adding an orthographic offset (OrthoDisplacement) “fixed” the problem. However, there is still a small offset in the rotation (particularly visible while moving up or down).
It’s probably not the best solution, thus my post on the forum.
everlastingseparateekaltadeta
Here’s the code that making the gameobject moving and tilting :
public void Move(Vector3 upMovement, Vector3 rightMovement)
{
upMovement *= _data.movementSpeed * Time.deltaTime;
rightMovement *= _data.movementSpeed * Time.deltaTime;
Vector3 heading = Vector3.Normalize(rightMovement + upMovement);
_transform.forward = heading;
_transform.position += upMovement;
_transform.position += rightMovement;
//Tilt the ship based on the direction
float angle = _data.shuttleTilt;
Vector3 orthoDisplacement = new Vector3(30, 45, 0);
if (upMovement == Vector3.zero && rightMovement == Vector3.zero) { orthoDisplacement = Vector3.zero; }
Vector3 axis = Vector3.Cross(heading, transform.up) + orthoDisplacement;
transform.Rotate(axis, angle);
Debug.DrawLine(transform.position, transform.position + heading * 3f, Color.red);
}
What is the best solution to deal with the Ortho view regarding gameobjects movement and rotation ?
Thanks and have a great day,
Paul
You can probably fix this by reparenting your spaceship to a blank GameObject and offsetting it until the rotation looks correct.
If you’re looking to smooth out that jerk effect, here are some notes on keeping a current and a desired value, and moving smoothly from one to the other:
Thanks ! I’m good for the smooth movement
Do you mean using a blank GO to determine the correct adjustement ? Shouldn’t it be the same as my ortho view ?
I’ve try to eyeball it several times, but I think that it’s a misscalcutiion. Anyway, offsetting the rotation looked a bit clumsy anyway, that’s why I’m searching another viable, and probably accurate, solution.
Based on what I can see, your rotation is not symmetrical to begin with.
So it’s likely a combination of factors.
btw that orthoDisplacement is an arbitrary point in space that is always applied as a positive value. I’m not sure I understood the point of doing cross between the heading and this vector, and I have a hunch that this result is not good (i.e. breaks symmetry).
I think he’s just looking for an axis that is at right angles to the heading and the line of sight. I do similar things with cross all the time. But I also agree that the orthoDisplacement he’s adding is probably not helpful. I certainly can’t see why adding a vector that happens to have components equal to the degrees of a rotation makes any sense. Have to wonder if it’s just a coincidence that his camera lands in a nearly workable place at all.
That’s my take. And it’s why I keep asking him for the coordinates. My (very tentative) guess is that he is near a working location, and this oddball vector he’s adding puts him there by dumb luck. What he needs is to be sure his camera is looking along the line he is submitting to his cross-product operation. I think it is looking slightly askew of that. But until we have more info, it’s just a guess.
Hi, thanks you for your answers !
Yep, this was a crude tentative… I thought that maybe, compensating the rotation of the ortho cam would somehow adjust the tilt perfectly.
So, my camera target is located at the center of my gameobject player : (0, 10, 0). The Actual Camera (a child of the camTarget) is located at : (-9, 9, -10). And the Rotation is : (30, 45, 0).
The camera is rotated, not the camTarget.
Since the beginning of this project, i’m bit confuse with orthographic camera and the offset of everything that must be aligned with the camera and not the world.
A cross product would have suffice in this situation, but when I try to figure out how to find the good axis for the cam view, I’m at lost. I can’t even eyeball it since the rotation axis in the scene aren’t aligned with the ortho view.
My heading direction already take account for the ortho rotation. I thought it was Ok to use it to tilt the ship.