- Home /
Question by
Trild123787898 · Jan 19, 2020 at 04:45 PM ·
rotationscript.joints
object rotation
how can I rotate an object that has a Configurable joint component
Comment
Best Answer
Answer by NVJOB · Jan 19, 2020 at 06:23 PM
Do as in the screenshot.
Add this script to "Object Rotation":
using UnityEngine;
public class Rotation : MonoBehaviour
{
public float rotSpeedAll = 3;
public float rotSpeedX = 0.5f;
public float rotLengthX = 5;
public float rotSpeedY = 0.5f;
public float rotLengthY = 7;
public float rotSpeedZ = 0.5f;
public float rotLengthZ = 9;
Transform tr;
float rtx, rty, rtz;
void Awake()
{
tr = transform;
}
void LateUpdate()
{
float timeTime = Time.time;
if (rotSpeedX != 0) rtx = Mathf.PingPong(rotSpeedX * timeTime, rotLengthX);
else rtx = 0;
if (rotSpeedY != 0) rty = Mathf.PingPong(rotSpeedY * timeTime, rotLengthY);
else rty = 0;
if (rotSpeedZ != 0) rtz = Mathf.PingPong(rotSpeedZ * timeTime, rotLengthZ);
else rtz = 0;
tr.Rotate(new Vector3(rtx, rty, rtz), rotSpeedAll * Time.deltaTime);
}
}
A simpler option if no settings are required:
using UnityEngine;
public class Rotation : MonoBehaviour
{
public float rotSpeed = 3;
Transform tr;
void Awake()
{
tr = transform;
}
void LateUpdate()
{
tr.Rotate(new Vector3(1, 0, 0), rotSpeed * Time.deltaTime); // new Vector3(1, 0, 0) - Direction of rotation
}
}
ex.png
(1.9 kB)
also does not change anything! you see, you give me a script that you want to use with a body on a twird, in my case it’s not so
Did you do as in the screenshot? You cannot rotate the object directly, you need to place what you want to rotate inside the object "joint".
This is an explanatory video - https://www.youtube.com/watch?v=dZbR2YZ6wnI
Perhaps you need to get a different effect?