Hi all,
I am facing a very wierd issue with respect to the movement of the object in 3D space. I am moving the X,Y value of the object using the coordinates received from a Playstation Move controller. The coordinates are being streamed to the playcanvas using a local socket server that receives 100 coordinates per second. Its handled in the below script.
var Logo = pc.createScript('logo');
Logo.extend({
postInitialize: function () {
var self = this;
this.step = 0;
this.speed = 2;
this.end = false;
this.once = false;
window.globals.socket.on('movedata', function (sensorValues) {
self.handleMovement(sensorValues);
});
},
handleMovement: function (sensordata) {
var valuesArr = sensordata;
var newXVal = sensordata[0];
var newYVal = sensordata[0];
// set position method
this.targetPos = new pc.Vec3(-26, newYVal, newXVal);
this.step = 0;
this.end = false;
},
updateOrientations: function (horizontal, vertical) {
this.targetPos = new pc.Vec3(this.entity.getPosition().x + horizontal.x, this.current.y + horizontal.y, this.current.z + horizontal.z);
this.step = 0;
this.end = false;
},
update: function (dt) {
if (!this.current || !this.target ) return;
if (this.end) return;
this.step += dt * this.speed;
if (this.step > 1) {
this.step = 1;
this.end = true;
}
this.entity.setPosition(this.targetPos);
}
});
// temp
Logo.targetPos = new pc.Vec3();
Logo.calculatedValues = new pc.Vec2(0,0);
Observing the above code, the handlemovement method is being called repeatedly as the sensor data is streamed. But the logo coordinates are updated in the screen only once or doesnt update every second. Most of the times, its updated once per second or lesser times. Any help is greatly appreciated. Many thanks.
Here is the project link - PlayCanvas 3D HTML5 Game Engine