Hey
I actually want to achieve something pretty easy. I want to tilt a platform based on the players input. like this:
so i tried to use transform.rotate for every key and this kinda works like this:
the problem i have now is, that it is can be rotated too much (so it goes threw the shadow) and it somehow also rotates around the y axis, so that the platform doesn’t stay isometric to the camera.
This lets you manipulate each axis separately, and keeping the Y-axis as 0 should stop it from rotating.
Please note that this is optimized for a joystick as it’ll use the sensitivity to rotate. If you use this code with a keyboard it’ll snap to each extreme. For keyboard you could do something like:
//Variables to store both axis
float hAxis;
float vAxis;
//Vertical and Horizontal axis from Input
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
//Add to each axis from key presses, using Clamp to keep the max/min set to 10/-10, so you don't over-rotate
vAxis = Mathf.Clamp(vAxis+v,-10f,10f);
hAxis = Mathf.Clamp(hAxis+h,-10f,10f);
//Rotate to match the new axis using EulerAngles.
transform.Rotate(new Vector3(hAxis,0f,vAxis), Space.Self);
I haven’t tested this as I don’t have your setup, but it should be enough for you to figure it out on your end.Hope this helps!
thanks! that helped a little bit :) now the platform is still somehow going crazy :D gif: http://www.gfycat.com/SophisticatedIllfatedGonolek so, the top is the Y axis and the sides are X and Z just fyi
The problem appears to be that because the rotations are being performed globally, rather than locally, rotating on multiple axes means mixing all rotations together inadvertently. This is a problem very easy to overlook when calculation order matters.
For example, If you rotate 90 degrees on the X-axis, then 90 degrees on the Z-axis, then -90 degrees on the X-axis, you’re currently sitting at a 90-degree rotation on the Y-axis as the result of those rotations. Following that up with a -90 degree rotation on Z-axis would leave you with your object standing upright.
thanks! that helped a little bit :) now the platform is still somehow going crazy :D gif: http://www.gfycat.com/SophisticatedIllfatedGonolek so, the top is the Y axis and the sides are X and Z just fyi
– Der_KevinAny chance you could Dropbox the file for me to take a look at? I understand if not :P
– HellsPlumbersure: https://www.dropbox.com/s/q5p6ueeazmy208h/tilttest.unitypackage?dl=0 i just made a striped down version. there should be 2 materials, one scene and one script. hope everything got included
– Der_Kevinthank you so much! thats perfect :)
– Der_KevinGlad I could help!
– HellsPlumber