- Home /
Trouble Projecting Vector on Plane
I am currently working on a third person movement system that allows for the player to walk on any surface, including angled, sideways or upside-down surfaces. One problem that arises from this is that I can't simply rotate the player on the y axis when I want to change what direction the player is looking. Instead, I need to rotate the player in a way that works regardless of the player's current rotation.
To do this, I found I could project the camera's view direction onto a conceptual plane perpendicular to the player's transform.up, to get a point to make the player look at.
I took the code example given in this post, and it worked almost perfectly, except for one problem; the player rotates towards the exact opposite direction I need. Rather than facing in the same direction as the camera, the player faces towards the camera itself. I'd really appreciate if someone could tell me what I'm doing wrong.
Here's the code I currently have implemented;
distanceToPlane = Vector3.Dot(transform.up, (cam.position - transform.position));
planePoint = cam.position - transform.up * distanceToPlane;
transform.LookAt(planePoint, transform.up);
Answer by ziggly001 · Mar 18 at 01:31 AM
I ended up looking into how to properly ProjectOnPlane a bit more, and found an article that framed it in a simpler, easier to understand way. I rewrote this section of my character controller after reading up on the topic, and it works perfectly now.
Here's the article for anyone who'd like to better their understanding of how this concept works.
Your answer
