[SOLVED] I'm having trouble getting the cannon to rotate without going through my tank

every time the cannon spins up or down it passes my tank and makes it fly.


w,a,s,d move the tank, left arrow and right arrow rotate the turret, and , up arrow and down arrow rotate the cannon.

Hi @naillywtsu_TT!

The kinematic rigidbody of the entity on the image below is pushing the dynamic rigidbody of your tank, when you rotate the cannon.


You can prevent this by limiting the cannon’s rotation, like I did in the script below.

var Cannon = pc.createScript('cannon');

// initialize code called once per entity
Cannon.prototype.initialize = function() {

// update code called every frame
Cannon.prototype.update = function(dt) {
   if (this.app.keyboard.isPressed(pc.KEY_DOWN)) {
      if (this.entity.getLocalEulerAngles().y > -5) {
         this.entity.rotateLocal(0, -0.2, 0);

   if (this.app.keyboard.isPressed(pc.KEY_UP)) {
      if (this.entity.getLocalEulerAngles().y < 50) {
         this.entity.rotateLocal(0, 0.2, 0);
1 Like

yea! it worked, the script solved the problem, thank you very much!

1 Like