【发布时间】:2015-03-14 08:43:02
【问题描述】:
嗨,我如何使子弹与处理中的对象发生碰撞? 子弹被发射并被平移和旋转 但是每当我尝试使用函数 dist() 它总是给我 0 作为向量的位置 如果我希望子弹使用距离与物体碰撞并使另一个物体消失,我如何获得正确的矢量位置?
这是代码
void move(){
passed = passed + time;
if (passed > bulletLife) {
alive = false;
}
forward.x = sin(theta);
forward.y = -cos(theta);
float speed = 15.0f;
velocity = PVector.mult(forward, speed);
side.add(forward);
void display(){
pushMatrix();
translate(side.x, side.y);
rotate(theta);
stroke(255);
ellipse(side.x, side.y, 30, 30);
popMatrix();
谢谢
【问题讨论】:
-
这段代码你在哪里使用 dist() 函数?可以发MCVE吗?
-
这是我计算距离的方法 PVector kool2 = coordinates();浮动 d = kool2.dist(位置) / 10; }//结束显示() PVector坐标() { PVector kool; kool = new PVector(side.x + cos(theta) * x2, side.y + sin(theta) * y2);返回库尔; }//结束坐标
标签: animation 2d processing collision interaction