- Home /
Object not following parent position when parent rotation is locked,Unable to move an object with its parent when rotation is locked
Hello,
I've been trying to build a 'pull heavy object' mechanic for my player.
The mechanic worked great by parenting the box object to my player when pull was set to true (indicated by a raycast and GetButton conditional). The issue was that the box would rotate along with the player, which I didn't like.
So, i disabled rotation on the player, which no longer allowed him to turn around while pulling. Also great. However, for some reason the box no longer follows his position even though I can see that it is parenting the box for a brief second before the player steps backward out of range.
Here's a quick sample of what I have:
if (Physics.Raycast(transform.position + new Vector3(0, 0.8f, 0), transform.forward, out hit, triggerDistance, layerMask) && hit.collider.gameObject.CompareTag("Draggable"))
{
isWithinRange = true;
}
if (isWithinRange && isGrabbing && Input.GetButton("Vertical") && Input.GetAxisRaw("Vertical") < 0)
{
isPulling = true;
}
if (isPulling)
{
draggableObject.transform.parent = gameObject.transform;
gameObject.GetComponent<vThirdPersonController>().lockRotation = true;
}
Essentially, I'm just using a raycast to determine if the object is within range of the player, setting grabbing to true if the player is holding the action button, then setting pulling to true if the player starts holds S or down to move backward. If pulling is true, I parent the box to the player and disable the player from rotating.
I'm thinking another option is to position the box relative to the player with an X and Z-axis offset but I can't seem to get this to work properly either. Any ideas would be super appreciated!
Your answer
Follow this Question
Related Questions
Stop Children of Instantiated Parent From Offsetting After Changing Position 0 Answers
Vector movement according to rotation glitching out at non-square angles. 0 Answers
How do I create an array of position vectorers to the player? 1 Answer
How do you change the values of Vector3 Offset (x, y, z) in script randomly/overtime? 0 Answers
How do I make and object's position and rotation independent again? 1 Answer