2014-06-24 28 views
1

我試圖從相機原點開始使用攝像機方向作爲射擊線。我希望能夠用int來改變鏡頭中的功率輸出量。用子彈物理學將物體施加在物體的方向上

在查看網頁上的各種代碼後,下面的代碼似乎就是我正在尋找的代碼。

obj.body.applyCentralImpulse(Vector3);  

哪裏的Vector3給部隊在X,Y,Z

以下是該方向的攝像頭看着

Vector3 dir = cam.direction; 

我怎麼能結合dir和所需要的力?

非常感謝。

+0

https://github.com/libgdx/libgdx/blob/master/tests/gdx-tests/src/com/badlogic/gdx/tests/ bullet/BaseBulletTest.java#L218 – Xoppa

+1

我以前曾經看過這個,但是正在尋找別的東西。感謝您的幫助,\t \t'Ray ray = cam.getPickRay(Gdx.graphics.getWidth()/ 2,Gdx.graphics.getHeight()/ 2); \t \t \t((btRigidBody)obj.body).applyCentralImpulse(ray.direction.scl(100f));'工作過一個款待 – Spriggsy

回答

0

這是它的工作對我來說:

float force = 10.0f; //but any value that works for you 
Vector3 dir = normalize(cam.origin + cam.direction) * force; //suppose your camera moves around 
body->applyCentralImpulse(dir);