Problem with path, planes and rotation

Hi for all, i want to use a both planes (crossed) with an image as bullet like :

but i can not able to take the correct angle (position and traslation is ok)

My code :
class Bullet

setInScene(){
    this.mat = new BABYLON.StandardMaterial(this.name+"_mat",this.scene);
    this.mat.diffuseTexture = new BABYLON.Texture("TEXTURES/Bullets/19.png");
    this.mat.allowShaderHotSwapping = false;
    this.mat.diffuseTexture.hasAlpha = true;
    this.mat.backFaceCulling = true;
    // let f = new BABYLON.Vector4(0,0, 0.5, 1); // front image = half the whole image along the width 
    // let b = new BABYLON.Vector4(0.5,0, 1, 1); // back image = second half along the width
      
    this.plane_h = BABYLON.MeshBuilder.CreatePlane(this.name+"_planeh", {height:1, width: 1.8, sideOrientation: BABYLON.Mesh.DOUBLESIDE},this.scene);
    this.plane_v = BABYLON.MeshBuilder.CreatePlane(this.name+"_planev", {height:1, width: 1.8, sideOrientation: BABYLON.Mesh.DOUBLESIDE},this.scene);   
    this.plane_v.material = this.mat;
    this.plane_h.material = this.mat;
    this.plane_v.setEnabled(false);
    this.plane_h.setEnabled(false);

  }//end of set in scene

method shoot :

shoot(_init, _angle_grads){
    // console.log( "llego a aqui ang "+ _angle_grads);
    this.angle.grad = _angle_grads;
    this.y = _init.y;
    this.angle.rad = BABYLON.Tools.ToRadians(this.angle.grad);
    // console.log( this.angle );
    this.pos_start = new BABYLON.Vector3(_init.x,_init.y,_init.z);
    let _end = utils.getFinalPointFromAngleAndDistance(_init.x,_init.z,this.angle.grad,this.distance);
    this.pos_end = new BABYLON.Vector3(_end.x,this.y,_end.z);

    this.plane_v.position = this.pos_start; 
    this.plane_h.position = this.pos_start;

    this.plane_v.setEnabled(true);
    this.plane_h.setEnabled(true);

    // let new_direct = this.pos_start.subtract(this.pos_end);
    // let normals = this.plane_v.getFacetLocalNormals();
    // let angle = BABYLON.Vector3.GetAngleBetweenVectors(this.pos_start, this.pos_end, BABYLON.Axis.Y);
    // console.log( "angless "+angle );
    // this.plane_v.rotation.y = angle;
    // this.plane_h.rotation.y = angle;

    this.plane_v.rotation.x = 0;
    this.plane_h.rotation.x = BABYLON.Tools.ToRadians(90);
    this.plane_v.rotation.y = BABYLON.Tools.ToRadians(this.angle.grad);
    this.plane_h.rotation.y = BABYLON.Tools.ToRadians(this.angle.grad);

    
    // let rotationQuaternion = BABYLON.Quaternion.RotationAxis(new BABYLON.Vector3(0, 1, 0), this.angle.rad);
    // this.plane_h.rotationQuaternion = rotationQuaternion;
    // this.plane_v.rotationQuaternion = rotationQuaternion;

    const myPoints = [this.pos_start,this.pos_end];  
    
    this.step=0;
    this.mode = true;

    // if( SHOW_PATHS ){
      // this.line = BABYLON.MeshBuilder.CreateLines(this.name+"_line", {points: myPoints});
      // this.line = BABYLON.Mesh.CreateLines(this.name+"_line", myPoints, this.scene);
    // }
    
    this.catmullRom = BABYLON.Curve3.CreateCatmullRomSpline(myPoints, 128);
    console.log( "algoo " );
    this.points = this.catmullRom.getPoints();

    this.catmullRomSpline = BABYLON.Mesh.CreateLines(this.name+"_bullet_path", this.points, this.scene);
    this.catmullRomSpline.color = new BABYLON.Color3(1, 1, 0);

    this.keysPosition = [];
    for (let p = 0; p < this.catmullRom.getPoints().length; p++) {
      this.keysPosition.push({
        frame: p,
        value: this.points[p]
      });

    }

    this.maxPoint=this.keysPosition.length;
    
    
  }//end of shoot

the bullet must be rotated like yellow line.

  • i tried many options… i am so tired with this…

i didn’t see any pattern at time of assign angle (in shoot method).

Are you able to reproduce the problem in a minimal PG? I think it will be difficult to help without a support.

I understand that you want to fire the bullet (the two planes) in a given direction but you cannot get to face the bullet in the desired direction. Right?

Alternative to math solution: parent bullet planes to common parent. Ensure mesh forward coincides with bullet tip. Then you can use mesh.lookAt(targetVec).

Or if you shoot the bullet from a gun anyway, parent the bullet to the gun.

Hi for everyone, thanks for your help, i solved it, for some reason the angle for bullets must be negative.

solved1


Ok bullets

1 Like