Rotate skybox with player
I am creating a top down space shooter and I am trying to rotate a cubemap skybox in relation with the ship. Since by default you can only rotate it by y-axis I used this to be able to rotate the skybox on multiple axis.
What I come up with so far is to get the velocity direction and magnitude of the player to set this rotation axis and angle of the skybox like this:
Vector3 targetVelocity = targetRigidBody.velocity;
Vector3 normTargetVelocity = targetVelocity.normalized;
if (normTargetVelocity.magnitude > 0) {
skyboxRotationAxis = new Vector3(normTargetVelocity.z, skyboxRotationAxis.y, -normTargetVelocity.x);
float rotationDampener = 0.005f;
skyboxRotationAngle = skyboxRotationAngle + targetVelocity.magnitude * rotationDampener;
RenderSettings.skybox.SetFloat("_Rotation", skyboxRotationAngle);
RenderSettings.skybox.SetVector("_RotationAxis", skyboxRotationAxis);
}
However, although the resulting end rotation seems correct, it snaps weirdly around when I change direction of the ship. Anyone got any ideas how I can fix this?
Your answer
Follow this Question
Related Questions
Rotate camera upward. 0 Answers
ROTATION STOPS when i move the char on the air! 0 Answers
Skybox is always pink 0 Answers
move object in a certain direction 0 Answers
Make GameObject rotate around another around random axis but with fixed distance 0 Answers