#Proper vector projection

1 messages · Page 1 of 1 (latest)

pulsar flame
#

Hello everyone,
I'm trying to project my Vector2 input onto a plane based on the rotation of my camera. But I don't know what I'm doing wrong.

I've made some drawings based on my situation
Essentially the plane (yellow) is at an angle towards the camera (blue).
I'm trying to figure out which direction on the plane corresponds to the up direction in my cameras view (green).
I want to basically use that direction in order to move an object along the plane based on my y-axis input.

But by using Vector3.ProjectOnPlane (targetCamera.transform.up, CursorPlane.normal ).normalized; I'm getting the wrong direction (red).

I feel like I'm going insane... any idea what I missed or did wrong?

olive swift
pulsar flame
#

Hm, I figured the projection was correct.
What I'm looking for is the vector that corresponds to the green one (based on camera.transform.up)
but on the plane

#

I thought you'd have to do that with projection

olive swift
pulsar flame
#

ohhh, I'll try that
thanks

pulsar flame
#

hmmm
didn't work...
the direction is going somewhere completely elsewhere than expected

#

goes to the back of the plane

olive swift
#

do you want the direction in world space or local space? you still have to project the Vector3 you get from the transform into your actual plane. But its impossible to know from your drawing which axis is the plane normal. E.g.

// camera-up in local space of the cursor plane transform
Vector3 localCameraUp = cursorPlane.transform.InverseTransformDirection(camera.transform.up);
// normal of the cursorPlane in the local space of its transform.
Vector3 localPlaneNormal = Vector3.forward;
// camera-up projected into the plane
Vector3 upInPlane = Vector3.ProjectOnPlane(localCameraUp, localPlaneNormal).normalized;
// 2D
Vector2 upInPlane2D = new Vector2(upInPlane.x, upInPlane.y);