Last active
January 19, 2024 02:13
-
-
Save karpatic/18d71d8f5ee379e7e86e70401ce4a87c to your computer and use it in GitHub Desktop.
Trig functions for an object to face a player
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Not Used | |
setInteraval(() => { | |
const p = parcel.getPlayersWithinParcel()[0] | |
let v1 = feature.position | |
let v2 = p.position | |
let angle = Math.atan2(v1.z - v2.z, v1.x - v2.x) | |
console.log(Math.PI / -2 - angle ) | |
let r1 = feature.rotation.y | |
console.log("R1: " + r1) | |
let newAngle = Math.PI / -2 - angle | |
console.log("New angle: " + newAngle) | |
let delta = newAngle - r1 | |
console.log("Delta: ", delta) | |
lr r2 = feature.createAntimation('rotation') | |
r2.setKeys([{ | |
frame:6, | |
value: feature.rotation.add(new Vector3(0, delta, 0) ) | |
}]) | |
feature.startanimation( [r2] ) | |
feature.rotation.y = newAngle | |
}, 400) | |
# - "Turn vox to face player' by Gvan` | |
# https://twitter.com/__gvan__/status/1530581206655442949 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment