anyone have any ideas or tutorials on how to make rotating platforms like
these


?
thanks
anyone have any ideas or tutorials on how to make rotating platforms like
these


?
thanks
Use Physics and learn child/parent relationships. For example the parent would be the middle and each platform would be a gameobject child offset. Then when you turn the parent, the child objects then rotate with an offset.
Once you have done this simple task, try connecting Physics2D platforms by using joints and so on (not child/parent). This is all achievable without any code.
I’ll look into that thanks
are you talking about hing joint 2d? Ive managed to get a platform to rotate around a box that way but The platform doesn’t stay flat.
Tick constraints on the rigidbody to prevent it rotating
no matter what i tick on the platform thats rotating around the center block x ,y or z it stops rotating around the center block
its doing the top when i would like the bottom this site only hosts for 10 min so might have to edit this post later
https://image.ibb.co/nsNQWQ/mockup.png
hmm no idea how to do that would take a contstant rotation I would think
No, but you’re just not reading up enough about joints to begin with, I bet you’ve set it up wrong. The platforms should not be children themselves, only their anchors which will be used to connect a joint to.
Then it’s a matter of finding the right joint type.
Scripting wise, you can also reset rotation each frame with Quaternion.identity, but I think there are huge holes in your experience and I’m thinking I’m doing more harm than good. You should spend time getting used to the different joints and behaviours.
Or maybe someone will come and help out ![]()
I just did this in a game. Check this video 30 seconds in
You need two objects. The first is the parent object, which rotates constantly. Attach this script “RotateByDegrees” to it.
then set it so it rotates 90* over 1 second, or something reasonably slow. Set the rotation to continuous if you don’t want it to pause between turns.
Next, take a child object, and parent it to the parent object, and offset it by position a bit. Give it the same settings as the parent, but negative in the degrees.
using UnityEngine;
using System.Collections;
public class RotateByDegrees : MonoBehaviour {
public float timeToReachTarget;
public float rotateByDegrees;
public float waitBetweenTurns;
public float cycleOffset = 0f;
private Vector3 startRotation;
private float clockworkRotation;
private Vector3 targetRotation;
private Vector3 currentRotation;
private float Percentage;
private float standin;
private bool ObjectMoving;
public bool RotateOnClick;
private float totalCycleLength;
private float cycle = 0f;
private float lastCycleValue;
private float completion;
private float remainder;
private float segments;
private float initialLocalRotationZ;
private bool newTry = true;
private float turnStartTime;
private float turnEndTime;
private float waitStartTime;
private float waitEndTime;
private float clockworkRemainder;
private float angleIwant;
private float rotationCompletion;
public bool continuous = false;
private float continuousAngle;
void Start()
{
startRotation = gameObject.transform.localEulerAngles;
initialLocalRotationZ = gameObject.transform.localEulerAngles.z;
}
public IEnumerator RotateDegrees(float degrees){
ObjectMoving = true;
Percentage = 0f;
startRotation = gameObject.transform.localEulerAngles;
targetRotation = startRotation + new Vector3 (0, 0, degrees);
currentRotation = startRotation;
while (Percentage<1f) {
standin = Mathf.Lerp (startRotation.z, targetRotation.z, Mathf.SmoothStep (0f, 1f, Percentage));
transform.localEulerAngles = new Vector3 (0f, 0f, standin);
Percentage += Time.deltaTime / timeToReachTarget;
yield return null;
}
transform.localEulerAngles = targetRotation;
yield return new WaitForSeconds(waitBetweenTurns);
ObjectMoving = false;
}
void OnMouseDown(){
if (RotateOnClick == true && ObjectMoving == false) {
StartCoroutine ("RotateDegrees", rotateByDegrees);
AudioSource.PlayClipAtPoint (Resources.Load("EasyToAccessSound/"+"TouchButton") as AudioClip, gameObject.transform.position);
}
}
void Update(){
if (RotateOnClick == false && rotateByDegrees != 0f) {
if (continuous == false) {
totalCycleLength = timeToReachTarget + waitBetweenTurns;
cycle = (Time.timeSinceLevelLoad + cycleOffset )% totalCycleLength;
turnStartTime = 0f;
turnEndTime = timeToReachTarget;
waitStartTime = timeToReachTarget;
waitEndTime = totalCycleLength;
rotationCompletion = Mathf.SmoothStep (0f, 1f, Mathf.Clamp ((cycle / timeToReachTarget), 0f, 1f));
clockworkRotation = (((rotateByDegrees / totalCycleLength)) * (Time.timeSinceLevelLoad + cycleOffset));
clockworkRemainder = clockworkRotation - (clockworkRotation % rotateByDegrees);
angleIwant = rotationCompletion * rotateByDegrees + clockworkRemainder + initialLocalRotationZ;
gameObject.transform.localEulerAngles = new Vector3 (0, 0, (angleIwant));
}
if (continuous == true) {
totalCycleLength = timeToReachTarget + waitBetweenTurns;
cycle = (Time.timeSinceLevelLoad + cycleOffset) % totalCycleLength;
turnStartTime = 0f;
clockworkRotation = (((rotateByDegrees / totalCycleLength)) * (Time.timeSinceLevelLoad + cycleOffset));
continuousAngle = clockworkRotation + initialLocalRotationZ;
gameObject.transform.localEulerAngles = new Vector3 ( 0, 0, continuousAngle);
}
}
}
}
If that’s too bloated, rotate the parent object any way you want. Then parent the child object to it, but attach a script that forces it’s rotation to always be zero.
using UnityEngine;
using System.Collections;
public class level : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
gameObject.transform.eulerAngles = new Vector3 (0f, 0f, 0f);
}
}
this does work pretty good however I have a issue , on the moving platforms I’ve made in the past I keep my player rigidbody attached to it by
void OnTriggerEnter2D(Collider2D other)
{
if (other.transform.tag == "MovingPlatform") {
transform.parent = other.transform;
}
}
void OnTriggerExit2D(Collider2D other)
{
if (other.transform.tag == "MovingPlatform") {
transform.parent = null;
}
}
so of course with your code my player rotates on the platform by itself which is funny
but wrong