I am trying to make a pong like game but i need to find the offset from the center of the paddle so that i can make it bounce differently depending on where it hits the paddle. How can i achieve this?
我试图做一个像乒乓球一样的乒乓球,但我需要找到从球拍中心的偏移量,这样我就可以根据它击中球拍的位置使其反弹。我怎样才能做到这一点?
1 个解决方案
#1
-1
Try:
// get the center of the paddle
var centerXpaddle = paddle.x - paddle.width/2;
var centerYpaddle = paddle.y -paddle.height/2;
if (objectThatHits.hitTestObject(paddle)) {
// get the current point of object
var offsetX = objectThatHits.x - centerXpaddle;
var offsetY = objectThatHits.y - centerYpaddle;
}
The first two lines get the center of the the paddle (it's current position minus half the width and half the height) and the second part is a "test" for when the "object that hits" hits the "paddle".
前两条线获得桨的中心(它的当前位置减去宽度的一半和高度的一半),第二部分是“测试”,当“击中的物体”击中“桨”时。
#1
-1
Try:
// get the center of the paddle
var centerXpaddle = paddle.x - paddle.width/2;
var centerYpaddle = paddle.y -paddle.height/2;
if (objectThatHits.hitTestObject(paddle)) {
// get the current point of object
var offsetX = objectThatHits.x - centerXpaddle;
var offsetY = objectThatHits.y - centerYpaddle;
}
The first two lines get the center of the the paddle (it's current position minus half the width and half the height) and the second part is a "test" for when the "object that hits" hits the "paddle".
前两条线获得桨的中心(它的当前位置减去宽度的一半和高度的一半),第二部分是“测试”,当“击中的物体”击中“桨”时。