The current project I’m stuck on consists of a Third-Person controller with animations embedded for movements. I have it successfully working multiplayer wise on another fork however I’ve came to a standstill once I’ve added virtual joysticks for mobile players.
Link to fork project here
Note: This virtual joystick is only visible from mobile browsers.
There are 2 main scripts that correlate with each other for it to work that being (PlayerMovement.js & virtualJoystick.js). The x, z values of Joystick needed to change the character position are from virtualJoystick.js yet I’ve created an event to send those values to PlayerMovement.js to actually make the change.
The problem is that the character is not moving in the correct direction as well as the proper animations needed are not playing. I also have a PlayerAnimationHandler.js script which applies the proper animations based on the direction the player is going but again this only seems to be working on Desktop and I would like for it to work on mobile browsers as well with the virtual joystick that I have embedded. The left stick is the root of the problem, the right stick simply controls the camera rotation.
PlayerMovement.js - Bottom of Script
// Desktop Movement of Player
if (x !== 0 || z !== 0) {
var pos = new pc.Vec3(x * dt, 0, z * dt);
pos.normalize().scale(this.speed);
pos.add(this.entity.getPosition());
var targetY = this.cameraScript.eulers.x + 180;
var rot = new pc.Vec3(0, targetY, 0);
this.entity.rigidbody.teleport(pos, rot);
}
// Touch JoyStick Movement of Player Event
var onPlayerTouchMove = function (x, z) { // z is really y
var touchSpeed = 0.0001;
// Left Joystick movement
if (x !== 0 || z !== 0) {
var pos = new pc.Vec3(-x * dt, 0, -z * dt);
pos.normalize().scale(touchSpeed);
pos.add(this.entity.getPosition());
var targetY = this.cameraScript.eulers.x + 180;
var rot = new pc.Vec3(0, targetY, 0);
this.entity.rigidbody.teleport(pos, rot);
}
};
// listen for the player touch move event
this.entity.script.touch.on('touchPlayerMove', onPlayerTouchMove);
};
I attempted to fork many similar projects that have a virtual joystick yet I’m having trouble figuring out how to execute this, I’ve been working at it for a week now and it has pressed me to move to another engine. I wouldn’t like to only because it’s a small issue but implementing it seems so much of a challenge.
I’m asking for proper guidance or anyone who can simply implement the fix. I’m usually one to do it on my own however there is a forum for a reason so why not utilize it? Thanks ahead of time, it’s much appreciated!