#grab physics

1 messages · Page 1 of 1 (latest)

velvet ice
#

making a thread

#

Do you need to know where your hand was in the last FixedUpdate, rather than where it was when you started the grab?

burnt hollow
velvet ice
#

I'm asking you how your game is supposed to work!

burnt hollow
#

like the locomotion?

velvet ice
#

I originally thought you wanted to know where the hand started

#

That would let you figure out where to position the player based on the current hand position, too

#

it wouldn't give you a velocity though

burnt hollow
#

so basically i use overlap sphere, if it overlaps a collider, and you grab it, when you grab it, you offset the player by (lastHandPos - handTransform) / Time.fixedDeltaTime

when ungrabbed, it stops it

lastHandPos (vector3), is set at the end of FixedUpdate, and player offset is at the start

what im trying to figure out is how to fix that jitter when grabbing a moving object, and how to make so the player moves with that grabbed object too

@velvet ice

velvet ice
#

okay, so you can do this at the end of FixedUpdate:

#
localLastHandPos = grabbed.InverseTransformPoint(handPos);
#

and then at the start of FixedUpdate:

Vector3 lastHandPos = grabbed.TransformPoint(localLastHandPos);
#

lastHandPos is a world-space position.

#

If the grabbed transform moved, then lastHandPos will have moved

burnt hollow
#

i have an attach point on the minecart, thats being set to handTransform when i grab the minecart

you mean grabbed as the object i grabbed? (aka attachPoint)

velvet ice
#

grabbed is the Transform of the object you grabbed

burnt hollow
#

okk

velvet ice
#

The idea is to record where your hand was from the point of view of the object

#

That way, no matter how the object moves, you can figure out the correct world-space position later

burnt hollow
#
void FixedUpdate(){
        LocalPlayer.GetGripHand(grabbingHand).handLastPosition = attachPoint.TransformPoint(localLastHandPos);
        
        //Lever Logic

        localLastHandPos = attachPoint.InverseTransformPoint(LocalPlayer.GetGripHand(grabbingHand).handTransform.position);
    }

i did this, brb

#

@velvet ice gurl youre truly the sigma one, thanks sm

#

(it works)

velvet ice
#

nice (:

#

The Transform methods can be super useful.

#

Any time you find yourself trying to "offset" something because you're trying to use a different point of view, you probably need a transform method

burnt hollow
#

i currently suck at physics in unity and transforms thats for sure

velvet ice
#

(but sometimes you just have to do it yourself)

#

i have a component that parents the knots of a Spline to transforms

#

so that the spline follows the transforms around

burnt hollow
#

i was just so desperate because i been trying to get this to work for so long i didnt think of different perspectives

velvet ice
#
            for (int index = 0; index < spline.Count; ++index)
            {
                BezierKnot knot = knots[index];
                Transform parent = transforms[index];
                positionOffsets.Add(parent.InverseTransformPoint(splineTransform.TransformPoint(knot.Position)));

                Quaternion knotWorldRotation = splineTransform.rotation * knot.Rotation;
                Quaternion toParentRotation = Quaternion.Inverse(parent.transform.rotation) * knotWorldRotation;
                rotationOffsets.Add(toParentRotation);
            }
#

mildly scary

burnt hollow
#

i got curvy splines

velvet ice
#

Yeah, unity splines