midpoint vector3 rotation

hi,

Imagine a line between your two hands.

I’d like to know the rotation at the mid-distance of those two hands.

Anyone knows how to do that ?

Thanks,

Based off of what you’re saying, I would start with something like this(it would help if you provided code).

void PsuedoCode() // Example purposes to lead you in the right direction.
    {
        var midPoint = Vector3.Distance(yourFirstPoint.position, yourSecondPoint.position);

        if (midPoint == 0.5f)

        {

            // Do stuff here.

        }
    }

I could think of a lot of ways you could do it. A couple would be a Raycast and using an empty gameobject(with a box collider) in between the two hands. Use the hit.point to get it that way. Probably not the most efficient way, but it’s a start.

Couldn’t you just use this.gameobject.transform.rotation?

let me explain it more precisely.

I want to constantly have the rotation of an imaginary point between your two moving hands.

Like if you were a telekinesist and controlling rotation of object in mid-air with the position of your hands.

If you put your right hand straight above your left hand, the floating object in between should rotate accordingly and have its right face up and left face down. The right face of the cube always facing the right hand and the left face of the cube always facing the left hand.

No matter how long the distance is between your two hands.

Wouldn’t setting the floating object as a parent of the two hands do what you want?

you can’t have multiple parents can you ?

OK, you can just add a rigidbody to the point between the hands and lock the rotation of the axis you don’t want to rotate. Then use this.gameobject.transform.rotation to know the rotation.

That’s exactly my question : how to get this point rotation ?

The only thing I have is two vector3 for each hand’s position which helps me determined the mid point’s position but not the midpoint’s rotation.

A quick look into the docs: Unity - Scripting API: Transform.rotation

float RotationX = gameObject.transform.rotation.x;

My bad, I I was thinking of something else. ha

My bad haha. I was thinking of precomps in AAE for some reason, guess it’s time to to hit the bed :p. If you want to do something a bit more dynamic and something that would probably work, use a Linecast. Here’s some pseudo code to lead you in the right direction. The “this” represents the floating object.

public GameObject rightHand;
public GameObject leftHand;
void MagicHands() // This is for example purposes
    {
        RaycastHit right;
        RaycastHit left

        var lineToRight = Physics.Linecast(this.transform.position, rightHand.transform.position, out right);
        var lineToLeft = Physics.Linecast(this.transform.position, leftHand.transform.position, out left);

        this.transform.rotation = right.transform.rotation * left.transform.rotation;

    }

haha no problem, thanks anyway.

I was thinking more of a formula involving vectors but just don’t know how to do that (to avoid raycasting).

After all, its just a line with a start and an end… there should be some way of knowing its orientation ?

Create a vector that points from one hand to another and then calculate the rotation based on that vector.

Vector3 h = hand2.position - hand1.position;
Quaternion rot = Quaternion.LookRotation(h);

KelsoMRK

thank
you !!