
[ad_1]
Game Development Stack Exchange is a query and reply web site for skilled and unbiased recreation builders. It solely takes a minute to enroll.
Anybody can ask a query
Anybody can reply
The greatest solutions are voted up and rise to the highest
Asked
Viewed
578 instances
I’m having a problem i can not appear to determine inside my code. What this code does in the intervening time is that it rotates the 3D Model across the z axis however i want it to rotate across the y axis. Any assist can be significantly appreciated.
void Update ()
{
Vector3 moveVector = (Vector3.up * joystick.Horizontal + Vector3.left * joystick.Vertical);
if (joystick.Horizontal != 0 || joystick.Vertical != 0)
{
remodel.rotation = Quaternion.LookRotation(Vector3.ahead, moveVector);
}
}
$endgroup$
3
It appears just like the feedback from three years in the past solved OP’s drawback, so I’m posting them as a solution so we are able to maintain this query from persevering with to be bumped.
It appears such as you need to do that:
void Update ()
{
// Construct a route within the horizontal airplane.
Vector3 moveVector = Vector3.ahead * joystick.Horizontal
+ Vector3.left * joystick.Vertical;
if (moveVector != default)
{
// Rotate across the y axis,
// to level our native z+ axis in that route.
remodel.rotation = Quaternion.LookRotation(moveVector);
}
}
$endgroup$
you possibly can additionally use:
float pace = 2f;
void Update ()
{
Vector3 moveVector = (Vector3.up * joystick.Horizontal + Vector3.left *
joystick.Vertical);
if (joystick.Horizontal != 0 || joystick.Vertical != 0)
{
remodel.eulerAngles
+= Vector3.up * Mathf.Atan(joystick.Horizontal) * Mathf.Rad2Deg * pace *
Time.deltaTime;
remodel.eulerAngles
+= Vector3.proper * Mathf.Atan(joystick.Vertical) * Mathf.Rad2Deg * pace *
Time.deltaTime;
}
}
you must also use Time.deltaTime for issues like this to decouple the simulationspeed from the frametimes, i’ve included that within the instance above.
$endgroup$
2
You should log in to reply this query.
Not the reply you are searching for? Browse different questions tagged .
lang-cs
[ad_2]