I’m trying to make it so when I press the up arrow key, it changes the euler y rotation to rotate up, and rotate down with the down arrow. There’s no rotate() function for euler angles, so i tried to do “setLocalEulerAngles(0, this.entity.getLocalEulerAngles + 1, 0)”. Whenever I try this though, it sets all the eulers to NaN.
This is the full script. The only part I need help with is the euler rotation parts when pressing the arrow keys.
var Camera = pc.createScript('Camera');
Camera.attributes.add('rotateSpeed', {type: 'number'})
Camera.attributes.add('ballThrown', {type: "entity"})
Camera.attributes.add('throwForce', {type: "number"})
// initialize code called once per entity
Camera.prototype.initialize = function() {
this.app.mouse.on("mousedown", this._onMouseDown, this);
this.app.mouse.on("mousemove", this._onMouseMove, this);
this.eulers = new pc.Vec3();
};
Camera.prototype._onMouseMove = function (e)
{
this.eulers.x -= e.dx
this.eulers.y -= e.dy
}
Camera.prototype._onMouseDown = function (e)
{
this.app.mouse.enablePointerLock()
var clone = this.ballThrown.clone()
this.app.root.addChild(clone)
clone.enabled = true
clone.setPosition(this.entity.getPosition())
clone.translate(this.entity.forward.clone().scale(1))
clone.rigidbody.type = 'dynamic'
clone.rigidbody.applyImpulse(this.entity.forward.clone().scale(this.throwForce))
this.entity.sound.play('throw')
}
// update code called every frame
Camera.prototype.update = function(dt) {
if (pc.Mouse.isPointerLocked())
{
this.entity.setLocalEulerAngles(this.eulers.y * this.rotateSpeed, 0, 0);
}
var keys = this.app.keyboard
if (keys.isPressed(pc.KEY_UP))
{
this.entity.setLocalEulerAngles(this.entity.getLocalEulerAngles() + 1, 0, 0)
console.log(this.entity.getLocalEulerAngles())
}
if (keys.isPressed(pc.KEY_DOWN))
{
this.entity.setLocalEulerAngles(this.entity.getLocalEulerAngles() - 1, 0, 0)
console.log(this.entity.getLocalEulerAngles())
}
};