Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 常量box2d实体一次移动到一个点_Android_Box2d_Andengine - Fatal编程技术网

Android 常量box2d实体一次移动到一个点

Android 常量box2d实体一次移动到一个点,android,box2d,andengine,Android,Box2d,Andengine,我有一个box2d物体在安德林。我想一次将这个物体从(0,0)移动到(100100)(恒定速度)。这怎么可能?我尝试了以下代码:this.body.setLinearVelocity(新向量2(1,0));但是它一直在不停地移动。我想沿着预定义路径移动最简单的方法是使用Body.setTransform(…)。这样我们基本上忽略了所有的力、摩擦力、扭矩、碰撞等,直接设定物体的位置 我不知道Andengine,所以这只是伪代码: public void updateGameLoop(float d

我有一个box2d物体在安德林。我想一次将这个物体从(0,0)移动到(100100)(恒定速度)。这怎么可能?我尝试了以下代码:this.body.setLinearVelocity(新向量2(1,0));但是它一直在不停地移动。

我想沿着预定义路径移动最简单的方法是使用
Body.setTransform(…)
。这样我们基本上忽略了所有的力、摩擦力、扭矩、碰撞等,直接设定物体的位置

我不知道Andengine,所以这只是伪代码:

public void updateGameLoop(float deltaTime) {
    Vector2 current = body.getPosition();
    Vector2 target = new Vector2(100, 100);

    if (!current.equals(target)) {
        float speed = 20f;
        Vector2 direction = target.sub(current);
        float distanceToTarget = direction.len();
        float travelDistance = speed * deltaTime;

        // the target is very close, so we set the position to the target directly
        if (distanceToTarget <= travelDistance) {
            body.setTransform(target, body.getAngle());
        } else {
            direction.nor();
            // move a bit in the target direction 
            body.setTransform(current.add(direction.mul(travelDistance)), body.getAngle());
        }
    }
}
public void updateGameLoop(float deltaTime){
Vector2 current=body.getPosition();
Vector2目标=新Vector2(100100);
如果(!current.equals(目标)){
浮动速度=20f;
矢量2方向=目标.sub(当前);
float distance to target=direction.len();
浮动行程距离=速度*增量时间;
//目标非常接近,因此我们直接将位置设置为目标

如果(距离)目标你的问题一点也不清楚。你想让它像传送机一样瞬间移动,还是以恒定的速度移动?身体不停地移动有什么问题?你想让它停止在两者之间移动吗?你有重力吗?也用新的矢量2(1,1)代替…我有一个身体。我想让它在(0,0)px和(100100)之间移动px不喜欢传送。我希望它在5秒内移动(V速度或2V速度)。不传送。假设你没有任何重力,身体的线性阻尼设置为0,你的像素与米的比率为1,一个简单的
身体。setLinearVelocity(新向量2(20,20))
应该做这项工作。但是如果没有关于场景的更多信息,没有人能够帮助你。这是重力。我的意思是将物体A点移动到B点。我尝试了这个物体。setLinearVelocity(新向量2(20,20))。但是当我使用它时,物体继续移动到无穷远。我希望物体停在某个点上。使用
setTransform()
移动对象会导致模拟无法最佳执行,并可能导致错误。