Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

102
Vistas
moveToObject sprite animation on Phaser 3

I have a character that has a click to point movement. I'm using MoveToObject I want to implement an animation to the sprite based on the direction it's moving similar to this code snippet below

if (this.cursors.left.isDown)
{
    this.player.setVelocity(-speed, 0)
    this.player.play('left-walk', true)
}
else if (this.cursors.right.isDown)
{
    this.player.setVelocity(speed, 0)
    this.player.play('right-walk', true)
}
else if (this.cursors.up.isDown)
{
    this.player.setVelocity(0, -speed)
    this.player.play('up-walk', true)
}
else if (this.cursors.down.isDown)
{
    this.player.setVelocity(0, speed)
    this.player.play('down-walk', true)
}

I'm guessing getting the current angle of the sprite but I can't seem to make it work. Thank you

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I have solved the following problem. Thank you!

 angles = Phaser.Math.Angle.BetweenPoints(avatar, target)
        var newAngles = Phaser.Math.RadToDeg(angles)
        console.log(newAngles)

        if (avatar.body.speed > 0)
        {
            if(newAngles <= -45 && newAngles >= -135) {
            avatar.anims.play('back', true)
            } else if (newAngles <= 45 && newAngles >= -45) {
                avatar.flipX = true
                avatar.anims.play('side', true)
            } else if (newAngles <= 135 && newAngles >= 45) {
                avatar.anims.play('front', true)
            } else if (newAngles <= 225 && newAngles >= 135) {
                avatar.flipX = false
                avatar.anims.play('side', true)
            }
            
            
            
            if (distance < 4)
            {
                avatar.anims.pause()
                avatar.body.reset(target.x, target.y);                
            }
        }       
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda