- Home /
Parenting Preventing Player Rotation
Hello everyone, I've come across a problem where parenting my player to a object prevents that player from rotating (turning), yet still allows the player to move forward and backwards. The strange thing is, I have used the same parenting method on other objects and this problem does not occur.
It would seem that the problem is somehow with the parent object itself, but I can't see any reason this object (or any object) in question would be any different from the others...
Below is the parenting script, any ideas are appreciated.
void OnTriggerEnter (Collider other)
{
if (other.tag =="Player")
{
other.transform.parent = transform;
}
}
The parenting code is fine. We use something similar to parent the player to moving platforms. The issue is probably in the Player Controller script where the rotation happens, maybe we could have a look at that as well?
@GameVortex: I've "kind of" solved the problem by changing the player rotation method from rigidbody.moverotation to .angularvelocity.
The issue seems to stem from the parented object being paranted to a animated bone (still don't know why, but .angularvelocity solves it).
Of course, this doesn't really solve the whole problem in that the player either doesn't inherit any momentum from the parent (even slow moving objects will result in the player slipping or sliding off of them), or the player inherits too much momentum (like if the parent object changes direction while the player is in mid air, the player will still follow it), and of course trying to "un-parent" after exiting the trigger (so the player would instantly loose all momentum). Still not completely sure what to do about all that.
@Boddole Couldn't you just get the momentum of the platform the player just left and add it to the momentum of the player?
depending on where your unparenting script would be, would affect the location for this:
Vector3 temp = platformReference.rigidbody.velocity;
playerReference.rigidBody.velocity += temp;
I don't know if this works. I can't test it right now, but it might work.
The problem is the platform is non-kinematic, therefore it has no velocity (it will always show as 0,0,0). So you have to create a velocity (usually by taking the current position and subtracting the previous position divided by delta time. I've actually posted a question about this, but I'll post it now for your reference:
http://answers.unity3d.com/questions/633426/problem-trying-to-apply-non-kinematic-velocity-to.html
Your answer
Follow this Question
Related Questions
C# Need Help converting from Rigidbody to Character Controller 0 Answers
C# DragRigidbody ArgumentException: get_main can only be called from the main thread 2 Answers
C# RotateAround for 2DRigidBodies 1 Answer
RigidBody Script Conflict 1 Answer
How to check if string array contains duplicates C# 1 Answer