Hello. Being fairly new to the world of coding, I am facing a problem.
I have the typical behavior of a human body to apply.
I have the upper body is a child of the lower body.
it is on the lower body that my script is attached.
The upper body must turn to + 45 ° - 45 ° (min… an max… var). If one tries to turn over, the entire body rotating at 45 ° (and so on).
For the upper body (upperCube), I did this:
var sensitivity : float = 5; var xRotation : float; var lowerCubeRotation : float; var upperCube : GameObject; var minUpperCubeXRotation = -45; var maxUpperCubeXRotation = 45; function Update () { var controller = GetComponent(CharacterController); xRotation += Input.GetAxis("Mouse X") * sensitivity; Rotation(); } function Rotation() { if (xRotation > maxUpperCubeXRotation){ } if (xRotation < minUpperCubeXRotation){ } upperCube.transform.localEulerAngles = Vector3(0, xRotation, 0); }
So the upper body rotates and if it reaches one of the limits, the lower body must perform a rotation of 45 ° (var lowerCubeRotation) over a period of 3 seconds (to be defined in a var) and the upper body returns to allignment with the lower body.
But how to code the part of the lower body. As I said, I suck.
I tested:
transform.Rotate(0, lowerCubeRotation, 0);
xRotation -= minUpperBodyXRotation;
which applies a rotation of 45 ° to transform (lower body), but instantly. And a rotation of the upper body to 0 (at the bottom allignment).
My problem lies in the duration of the rotation. I want it to end after x seconds, not immediately.
need help please.
(post on unity forum)
use google translate