Question by
Monsterwald · Jul 21, 2021 at 10:09 PM ·
rotationrotatearound
Pendel around a pivot point
Okay I managed to create this nice script, it works, the ball swings back and forth as it should. However, I used a parent gameObject to achieve this effect, which is no longer possible, therefore I have to find another way. I have to swing back and forth around a pivot point. HingeJoints are not allowed. Anyone an idea?
public class Pendulum : MonoBehaviour
{
[SerializeField] Transform pivot;
public float maxAngleDeflection = 30f;
[HideInInspector] public float maxAngleDeflectionCache;
public float speedOfPendulum = 3f;
[HideInInspector] public float speedOfPendulumCache;
private void Start()
{
speedOfPendulumCache = speedOfPendulum;
maxAngleDeflectionCache = maxAngleDeflection;
}
private void Update()
{
float angle = maxAngleDeflection * Mathf.Sin(Time.time * speedOfPendulum);
pivot.localRotation = Quaternion.Euler(0, 0, angle);
transform.eulerAngles = Vector3.zero;
}
}
Comment
Your answer
Follow this Question
Related Questions
Limit Rotation with RotateAround on 2 axis 0 Answers
Make GameObject rotate around another around random axis but with fixed distance 0 Answers
Why does RotateTowards rotate in an "orbit" rather than on the spot? Help me understand! 0 Answers
Manual RotateAround 0 Answers
constant rotation using keypress 0 Answers