Hey Unitarians!
In my game, I have a block called a swing block. The block part of it attaches to the ceiling of the game and the cord that is attached to it rotates constantly. It moves back and forth like a never-ending pendulum. At least, that’s what it should do.
What I have right now is that the cord of the swing rotates around the swing block, as it should, but it keeps going all 360 degrees - making a circle. This is probably because it is in the update function. I want it so that after 30 degrees of moving to the left, it switches direction and moves to the right, until it reaches 30 degrees in that direction, and switches back. How would I do this?
Currently my script:
using UnityEngine;
using System.Collections;
public class SwingBlock : MonoBehaviour {
public float RotateSpeed = 100;
public float angleMax = 30.0f;
private Transform SwingRoot;
//private Transform EndRoot;
void Start () {
SwingRoot = this.transform.parent.gameObject.transform;
}
void Update () {
//Rotation controller
transform.RotateAround (SwingRoot.position, Vector3.forward, RotateSpeed * Time.deltaTime);
}
}