[SOLVED] Tween Script Rotating Entity Very Less?

Hello,

I am trying to tween a turret of a tank model to move up and down smoothly. The tween works, but it’s rotating in a very limited manner, regardless of the rotation value I put in. The following is how I approached it - https://playcanvas.com/editor/code/768979?tabs=43349961

LAUNCH - https://launch.playcanvas.com/1099550?debug=true

EDITOR - https://playcanvas.com/editor/scene/1099550

How do I fix this?

Hi @XKRS-GT,

The reason the tween doesn’t work is because in another script, in tank.js, you override the rotation of the turret each frame. If you comment out lines 47 & 48 it works correctly:

Tank.prototype.update = function(dt) {
    var position = this.app.root.findByName("playbot").getPosition();
    // this.gun.lookAt(position);
    // this.gun.rotateLocal(0, 180, 0);

Hi @Leonidas, thanks for the reply. I require the turret to point at the capsule though, so those lines are required. Is there any alternate way of approaching this? I thought this would work since the tween was on the parent entity, while the lookAt code was on the turret itself.

So, yes, your logic is correct but I think you should do it in the opposite way:

  • have the parent entity (name tweened) look at per frame
  • add the tweenRotation.js script to the turret entity directly

That way the turret model will tween, and its base point based on the parent entity will look at the point you specify.

2 Likes

Thanks a lot for this, will give it a go. Invoking @DevilZ to take a look and try it on the project.

2 Likes

I can now confirm that this works for us @Leonidas, thank you for helping @XKRS-GT out with this.

2 Likes