hello guys,
I am trying to figure out if I can rotate pc.VEC 3 of the entity. If the entity is in front like normal, the screenToWorld works good. Here is some pictures:
As you can see, when i throw forward or to sides, the ball corectlly follow the x positions.
But if I tween the ground with the camera to left or right side, when I throw the ball, that shoot in wrong way.
Here is pictures:
SIde Left:
Side right:
As you can see now, the ball follow wrong direction of X position. Here is the code:
BallMovement.prototype.onMouseMove = function(event){
// console.log("Y: ",event.y, "X: ", event.x);
if(this.isMousePressed ) {
var context = this;
var canTeleport = true;
var cameraEntity = this.app.root.findByName('Camera');
this.pos = new pc.Vec3();
this.pos2 = new pc.Vec3();
this.pos3 = new pc.Vec3();
//this.counterMouse();
if(CameraCollision.changePositions ==1 && this.isBallClicked && canTeleport) {
var depth = 7.1;
cameraEntity.camera.screenToWorld(event.x , event.y ,depth, this.pos);
this.ball.setLocalPosition(this.pos.x, this.pos.y, this.ball.getLocalPosition().z);
}
else if(CameraCollision.changePositions == 2 && this.isBallClicked && canTeleport) {
var depth2 = 7.1;
cameraEntity.camera.screenToWorld(event.x , event.y,depth2, this.pos2);
this.ball.setLocalPosition(this.pos2.x , this.pos2.y , this.ball.getLocalPosition().z);
}
else if(CameraCollision.changePositions ==3 && this.isBallClicked && canTeleport) {
var depth3 =7.1;
cameraEntity.camera.screenToWorld(event.x , event.y ,depth3, this.pos3);
this.ball.setLocalPosition(this.pos3.x , this.pos3.y , this.ball.getLocalPosition().z);
}
this.screenCheckY = event.y;
}
};
I tried to rotate the ball after teleport, but not working. Also i tried multiply and divide the event.x on change position 2, which is right possition, and change possition 3, which is left possition. Like there:
else if(CameraCollision.changePositions == 2 && this.isBallClicked && canTeleport) {
var depth2 = 7.1;
cameraEntity.camera.screenToWorld(event.x /1.2 , event.y,depth2, this.pos2);
this.ball.setLocalPosition(this.pos2.x , this.pos2.y , this.ball.getLocalPosition().z);
}
else if(CameraCollision.changePositions ==3 && this.isBallClicked && canTeleport) {
var depth3 =7.1;
cameraEntity.camera.screenToWorld(event.x *1.1 , event.y ,depth3, this.pos3);
this.ball.setLocalPosition(this.pos3.x , this.pos3.y , this.ball.getLocalPosition().z);
}
Its working, but just on one resolution, and I need to fix it and change this numbers on every resolution, which is not good and not working correctly.
I think, that i need rotate the Balls pc.Vec3, but I dont know if is there some option for that.
If you have some solution for that, please share with me.
Thank you.