[ad_1]
I discovered and examined many alternative implementations when looking for this matter, however my use case appears to be barely totally different.
I’ve a static digital camera, however the participant can transfer freely across the display.
When the participant is within the centre of the display, my calculation form of works wonderful, as seen under.
However, once I transfer the participant to a nook (backside proper nook on this case), it does not face the cursor. Seems just like the calculation is ignoring the participant’s place, and solely bearing in mind the cursor place in relation to the window.
My code is applied in Rust (with Bevy Engine), however I’m positive the logic will be tailored from any language.
let window_size = Vec2::new(window.width(), window.top());
let distinction = mouse_position.prolong(0.0) - window_size.prolong(0.0) / 2.0 - participant.translation;
let angle = distinction.y.atan2(distinction.x) + PI;
*transforms.get_mut(sport.participant.entity.unwrap()).unwrap() = Transform {
translation: participant.translation,
rotation: Quat::from_rotation_y(angle),
..default()
};
Note1: .prolong(0.0) converts it from Vec2 to Vec3 by including 0.0 as z.
Note2: participant.translation is a Vec3 with the participant’s place on the display.
[ad_2]

