Hey there, thank you for dropping by my question.
Are you in need of freezing a rotation, this code might work:
using UnityEngine;
using System.Collections;
public class DenyRotation : MonoBehaviour {
Quaternion origRotation;
Transform mTransform;
void Awake () {
mTransform = transform;
origRotation = mTransform.rotation;
}
void LateUpdate () {
mTransform.rotation = origRotation;
}
}
However, for me it didn’t.
I’m stuck with a bit trickier problem.
This problem happened during the creation of a RopeSwing. Freezing the Z rotation makes sure my player stays upstraight, but it influences the swing physic.
Unfreezing it makes the player go ham.
Hardcoding it with the code above makes the player go even more ham.
The issue is explained below with Images!
[32153-main+issue.png|32153]
Well, if Freezing Z is the devil, why not turn it off? Well:[32154-main+issue+part+2.png|32154]
The hierarchy is shown in the picture above, in case the idea wasn’t clear yet.
Also, yes there are grammar faults, no I didn’t want to repaint them for this post when I found out, my apologies.
My Question is:
How can I Freeze the Rotation of PhotonPlayer without it influencing the Swing Physics?
Alternatively:
How can I Freeze the Rotation of PhotonPlayer’s Childs or Set them to be the inverted delta of their parent rotation, to give the illusion they’re not rotating
Note, I’ve tried the following code already for the alternative option, which doesn’t seem to work
using UnityEngine;
using System.Collections;
public class DenyRotation : MonoBehaviour {
Quaternion origRotation, origRotationParent;
Transform mTransform, mParentTransform;
void Awake () {
mTransform = transform;
mParentTransform = transform.parent;
origRotation = transform.rotation;
origRotationParent = transform.parent.rotation;
}
void LateUpdate () {
mTransform.rotation = Quaternion.Euler(
origRotation.eulerAngles.x - origRotationParent.eulerAngles.x + mParentTransform.rotation.eulerAngles.x,
origRotation.eulerAngles.y - origRotationParent.eulerAngles.y + mParentTransform.rotation.eulerAngles.y,
origRotation.eulerAngles.z - origRotationParent.eulerAngles.z + mParentTransform.rotation.eulerAngles.z);
}
}
If you have any ideas, I would really really appreciate it
Fire away! <3
CONCLUSIONAL EDIT:
The feature hasn’t been entirely resolved, however, the rotation inversion wasn’t all that hard.
For those out there seeking specific similar answers, here’s the updated code for the rotation inversion.
using UnityEngine;
using System.Collections;
public class DenyRotation : MonoBehaviour {
// Private variables for the transforms (Why? Normally .transform acts as a GetComponent, ieuw!!)
Transform m_Transform, m_ParentTransform;
void Awake ()
{
// Store the transforms in our private variables
m_Transform = transform;
m_ParentTransform = transform.parent;
}
void LateUpdate()
{
// Apply inverse rotation of the parent
m_Transform.localRotation = Quaternion.Inverse(m_ParentTransform.localRotation);
}
That code will work just fine for the rotation inversion, note that you’ll need to seperate the parent object and it’s childs by a single object in between which holds the DenyRotation script, that way you only have to apply this script once.
In the end, the grapple system worked quite well aside from the fact that there wasn’t any pulling up towards the grapple point. Many such as myself believe that having a pull towards the grapple point will allow for more flexibilty and increasal of speed with well timed grapples, which is kind of what we wanted.
My most accurate guess, along with the well written answer by scribe below would be to use the anchor system correctly instead of the current Hinge and fixed joint system that I have now.
I had some tryouts with the anchor system which actually worked quite well too, but I didn’t come to find how to implement this with a configurable joint before I had to get back to my multiplayer networking duties for my internship.
In the end the grapple system was scrapped in order to restore a more balanced movement system.
Even though I will miss it, I’m sure you can pull off making a proper grapple system if you Really know what you’re doing with Anchors.
If time allows me to, I’ll make a tutorial in the future.
For now I’ll honor scribe’s attempt at solving my issue by accepting his answer, because surely for others in some cases his solution should have perfect outcomes.
Thank you very much for reading, I hope this article will help you with your own programming journeys.