So with gamepad controls on here, of the joysticks there is just X or Y, no forward or back of each stick, so i need help with a way to detect if the angle is positive or negative and move accordingly, anybody able to help me code this
Hi @Gavin_Durbin ,
This example implements gamepad support for moving the player:
https://playcanvas.github.io/#/camera/first-person
You can inspect the code here, on how that works:
////////////////////////////////////////////////////////////////////////////////
// First Person Character Controller //
////////////////////////////////////////////////////////////////////////////////
var CharacterController = pc.createScript('characterController');
CharacterController.attributes.add('speed', { type: 'number', default: 5 });
CharacterController.attributes.add('jumpImpulse', { type: 'number', default: 400 });
// initialize code called once per entity
CharacterController.prototype.initialize = function () {
this.groundCheckRay = new pc.Vec3(0, -1.2, 0);
this.rayEnd = new pc.Vec3();
this.groundNormal = new pc.Vec3();
this.onGround = true;
this.jumping = false;
};
CharacterController.prototype.move = function (direction) {
if (this.onGround && !this.jumping) {
This file has been truncated. show original
4 Likes