Hello guys, i hope that you have wonderfull day again, but I need help again with coding. If you have some time for that, i will be thankfull.
I have simple basketball game, where ball will throw on some direction on mouse up or touch end. Now its working like when it mouse is pressed, and Ball is clicked ,where Im using do Ray cast function, after som Y height it will automaticaly throw to basket hoop on some X direction. But that apply impulse is fixed to power Y and Z. But i want set up some power, where Y and Z applyimpulse depends on where was touchend or mouse up fired. Like if Touchend or Mouse up was in some Y height, than Y and Z power will be some number. If these events was higher, power will be higher too. But its not working because i dont know how can i put in my code Mouse up event. Because now is shooting this ball when its just mouse down klicked, so this ball is throwing on first. lowest Y height… But how can i set up ,that after if its was mouse down and also mouse up , than just throw with that power in area, where I left my finger or mouse.
Like here is some code:
BallMovement.prototype.onMouseMove = function(event){
// console.log("Y: ",event.y, "X: ", event.x);
if(this.isMousePressed ) {
if(event.y <= window.innerHeight/1.4 && event.y > window.innerHeight/1.5 && this.canShot && this.isBallClicked ) {
this.app.fire('camera::followBall');
this.shotBallPC();
//throwing apply impulse power
this.entity.rigidbody.applyImpulse(this.pos.x*2.2, 5.8, - 3.4);
}else if(event.y <= window.innerHeight/1.5 && event.y > window.innerHeight/1.7 && this.canShot && this.isBallClicked ) {
this.app.fire('camera::followBall');
this.shotBallPC();
// throwing apply impulse power
this.entity.rigidbody.applyImpulse(this.pos.x*2.2, pc.math.random (5.6, 5.8), - 3.4);
}else if(event.y <= window.innerHeight/1.7 && event.y > window.innerHeight/1.9 && this.canShot && this.isBallClicked ) {
this.app.fire('camera::followBall');
this.shotBallPC();
// throwing apply impulse power
this.entity.rigidbody.applyImpulse(this.pos.x*2.2, pc.math.random (6, 6.2), - 3.4);
}
}
};
How can I do that? I hope that jou could understand my miserable English.
If you have some solution, please share with me your knowledge.
Thanks.