#Is it possible to project a Vec3 onto a plane?

6 messages · Page 1 of 1 (latest)

normal nebula
#

I have a particular 3d view where I want to slide the camera forward parallel to a plane. It starts slightly elevated above the plane and I use looking_at to look down at the origin. So the camera perspective is not normal to the origin and it's not parallel, it's down at an angle. I think to do this I'd like to...

fn system(camera: Query<&mut Transform>) {
    camera.transform = camera.transform.forward().project_onto(<xz plane>)

Because if I can only use the projection onto the plane the y value will never change. What's the best way to calculate 'forward' and 'backward' with staying parallel to the xz plane?

teal anvil
#

I have a question. Is your camera the child of an entity? If not you can just move it using translations with the y component at 0. Or I misunderstood what you meant

#

Like so tansform.position += Vec3 { x, y: 0f32, z };

teal anvil
#

But if you want the forward direction just do that : ```rust
let forward = {
let mut fwd = -camera.transform.local_z();
fwd.y = 0;
fwd.normalize()
};

#

Be aware that the query you showed here will not run for cameras only. It will run on any entity that has a Transform component.

#

and backward is the same as forward but multiplied by -1