I’m having a really hard time trying to create bloxorz movement within playmaker. I first set up a really large state machine with itween only to realise that this causes game breaking gimbal locking.
Has anyone successfully created these kind of controls?
Bloxorz video example movement.
Note: i’m not adverse to writing a C# script to achieve this.
I know nothing of Playmaker and remember even less about iTween. Since you don’t post any code, i can give you just pointers about the rotation (not that i would give you a fully working implementation anyways
)
Because of the inherent issues related to rotation order and gimbal locks when using euler angles, you shouldn’t use them when doin sequences like this (in case you tried to).
So basically you have 2 options.
A) Use Transform.RotateAround() to rotate your object around it’s own center.
Quaternion startOrientation;
void Update() {
if (Input.GetKeyDown(KeyCode.LeftArrow)) {
StartCoroutine(Rotate90(Vector3.forward));
} else if (Input.GetKeyDown(KeyCode.RightArrow)) {
StartCoroutine(Rotate90(Vector3.right));
}
}
private IEnumerator Rotate90(Vector3 axis) {
startOrientation = transform.rotation;
float amount = 0;
while (amount < 90) {
yield return new WaitForEndOfFrame();
var increase = Time.deltaTime * 90;
amount += increase;
transform.RotateAround(transform.position, axis, increase);
}
transform.rotation = startOrientation;
transform.RotateAround(transform.position, axis, 90);
}
B) Make a Quaternion that creates a rotation around a certain axis and multiply your rotation with it. (this might be better because this doesn’t affect the position of the object whereas RotateAround might)
Quaternion startOrientation;
void Update() {
if (Input.GetKeyDown(KeyCode.LeftArrow)) {
StartCoroutine(Rotate90(Vector3.forward));
} else if (Input.GetKeyDown(KeyCode.RightArrow)) {
StartCoroutine(Rotate90(Vector3.right));
}
}
private IEnumerator Rotate90(Vector3 axis) {
startOrientation = transform.rotation;
axis = transform.InverseTransformDirection(axis);
float amount = 0;
while (amount < 90) {
yield return new WaitForEndOfFrame();
amount += Time.deltaTime * 90;
transform.rotation = startOrientation*Quaternion.AngleAxis(amount, axis);
}
transform.rotation = startOrientation * Quaternion.AngleAxis(90, axis);
}