gpt4 book ai didi

java - LIBGDX RayCast : how do i stop the ray?(如何返回世界上想要的灯具)

转载 作者:行者123 更新时间:2023-11-30 02:42:03 25 4
gpt4 key购买 nike

请你帮我理解一下,

当光线转换撞到墙上时,如何停止光线转换?

这么说吧:

$==player, #==wall, %==Enemy, RayCast == ------.

我有这个水平:

___________________________


#
#
% -----#---$---
___________________________

在这种情况下如何阻止敌人向我射击?

我怎样才能停止光线转换“看看墙壁固定装置后面有什么”?

现在我只得到它们:

     RayCastCallback callback= new RayCastCallback() {
@Override
public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) {

if (fixture.getFilterData().categoryBits == Application.PLAYER){
return fraction;
}


if (fixture.getFilterData().categoryBits == Application.ENEMY){
return fraction;
}

return 0;
}
};


world.rayCast(callback, p1, p2);

那么是可以实现这一目标的分数吗?如果是这样,怎么办?

非常感谢!

最佳答案

通过这种方法,它可以满足我的需要:

private static final int NOTHING = 0;
private static final int WALL = 1;
private static final int PLAYER = 2;
private int type = NOTHING;
private Vector2 position;

@Override
public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) {

if (fixture.getFilterData().categoryBits == Application.WALL){
type = WALL;
}
if (fixture.getFilterData().categoryBits == Application.PLAYER){
type = PLAYER;
}

return fraction;
}

所以当我打印类型时:

System.out.println(this.rayCastStatus);

结果将是当光线转换撞到墙壁时停止光线转换。

好吧,并不是真的停下来,换句话说,只是为了得到我需要的结果,在这种情况下,当墙首先出现时,不是打印玩家。

来自文档,关于返回:

public interface RayCastCallback {
/** Called for each fixture found in the query. You control how the ray cast proceeds by returning a float: return -1: ignore
* this fixture and continue return 0: terminate the ray cast return fraction: clip the ray to this point return 1: don't clip
* the ray and continue.
*
* The {@link Vector2} instances passed to the callback will be reused for future calls so make a copy of them!
*
* @param fixture the fixture hit by the ray
* @param point the point of initial intersection
* @param normal the normal vector at the point of intersection
* @return -1 to filter, 0 to terminate, fraction to clip the ray for closest hit, 1 to continue **/
public float reportRayFixture (Fixture fixture, Vector2 point, Vector2 normal, float fraction);
}

关于java - LIBGDX RayCast : how do i stop the ray?(如何返回世界上想要的灯具),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41369547/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com