Hey thar!
I’ve been trying to modify a mouse look script that changes rotation of an object based on a top down view plane. I’ve made some changes in attempt to make the plane work on the xy axis instead of the xz axis.
Script can be found here http://www.unifycommunity.com/wiki/index.php?title=LookAtMouse
The plane is created via
var playerPlane = new Plane(Vector3.up, transform.position);
which creates a plane on the xz axis, but I’m wondering how you’d create it for the xy axis for a 2d side scroller game.
Thanks in advance
Slingthor
So what’s happening with this statement:
var playerPlane = new Plane(Vector3.up, transform.position);
is that a plane is being created with its normal in the positive Y direction (Vector3.up) that passes through the point transform.position
(the transform of whatever the script is being attached to).
To flip it into a different axis, you just supply a different vector as it’s normal (the first parameter). For reference, here’s the Plane constructor docs. So to take it into the XY axis, you would use a normalized vector3 such as Vector3.right as follows:
var playerPlane = new Plane(Vector3.right, transform.position);