Thanks for asking your question!
Once you have finished, please close your thread.
Use the /close command or button below.
1 messages · Page 1 of 1 (latest)
Once you have finished, please close your thread.
you can use a tick event and delta value by which u rotate entity
lastrot = null
delta = 0.5
onTick():
if not lastrot:
lastrot = player.rot
return
player.rot = rot + delta
i have only an problem on that, i have never used an tick event or delta value before.
could you maybe show me how to use those?
if you explain what exactly u want, then
My plan is that when the entity ( that is floating and moving ) when it turns, it does not do it suddenly, but little by little, that is, more slowly.
function fromAngle (pitch, yaw, distance = 1) {
let pitchRad = this.degreeToRadians(pitch)
let yawRad = this.degreeToRadians(yaw)
let sinYaw = Math.sin(yawRad)
let sinPitch = Math.sin(pitchRad)
let cosYaw = Math.cos(yawRad)
let cosPitch = Math.cos(pitchRad)
return {
x : distance * -sinYaw * cosPitch ,
y : distance * -sinPitch ,
z : distance * cosYaw * cosPitch
};
}
function toAngle (x, y, z) {
let magnitude = Math.sqrt(x*x + y*y + z*z)
x /= magnitude
y /= magnitude
z /= magnitude
let pitch = this.radianToDegrees(Math.asin(-y))
let yaw = this.radianToDegrees(Math.atan2(-x, z))
return { pitch, yaw }
}
function rotateEntitySlow (entity, targetRotation, duration = 1) {
let delta = 1 / duration
let v = fromAngle( targetRotation.x, targetRotation.y )
let t = 0
return new Promise( resolve => {
system.run( function runnable() {
if (t <= 1) {
system.run( runnable )
} else {
resolve()
}
let { x, y, z } = fromAngle( entity.rotation.x, entity.rotation.y )
x += (v.x - x) * t
y += (v.y - y) * t
z += (v.z - z) * t
let { pitch, yaw } = toAngle( x, y, z )
entity.rotation.x = pitch
entity.rotation.y = yaw
t += delta;
} )
} )
}
let targetRotation = { x: 0, y: 0 }
async function rotate() {
await rotateEntitySlow( player, targetRotation, 10 )
console.warn( 'rotation done' )
}
rotate()
@sturdy cove
ye
test it for errors
cuz i dont test ingame
rotateEntitySlow() is the main function it takes enity, target rotation and duration in ticks
if u want to run something after rotating is done use a async function with await
like shown in example
on top
alr thanks
here?
I'm so sorry if I don't know much about it, I've never done anything like this before
thats not script api
thats other thing
thats more of #old-animations thing scripting is a #old-script-api thing
oh
well u was not clear what ur doing but i think u are just trying for #old-animations not #old-script-api