Home:ALL Converter>Phaser 3 : sprite movement like Endless Sky NPC

Phaser 3 : sprite movement like Endless Sky NPC

Ask Time:2019-10-22T23:58:29         Author:JTInfinite

Json Formatter

I'm trying to replicate the NPC movement in Endless Sky. Checkout Endless Sky Github's Repository using Phaser 3.

The characteristic of the NPC is that they have drag and rotate to face the direction they intend to travel. I can do this with the player character using

player.body.setAngularVelocity(0);
player.body.setAcceleration(0)
scene.physics.velocityFromAngle(player.angle - 90, 400, player.body.acceleration)

But I can't seem to get it right with an npc - and by "get it right" I mean a smooth movement of the sprite turning/tweening to face the new coordinates and then moving towards it.

The closest I had was the sprite seemed to be moving correctly but the image/texture of the sprite was frantically changing angle, sometimes doing a 360 rotation. Perhaps I have a fundamental misunderstanding of the body.angle / body.rotation as well as the math involved?

At the moment, I am passing the npc a random vector to travel to:

 enemy.stateMachine.transition('patrolling', [Phaser.Math.Between(-3500, 3500), Phaser.Math.Between(-3500, 3000)])

-3500 and 3000 being the bounds of my game world.

Any help appreciated.

Author:JTInfinite,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/58508151/phaser-3-sprite-movement-like-endless-sky-npc
yy