- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 Jmonkey 编程的新手,我想问一个关于碰撞交互的问题,因为我的代码似乎从地形中找到了可能的碰撞,我不知道如何解决这个问题。我的目标是玩家作为第一个被检测到的人,如果他与敌人的幽灵控制相撞以显示一条消息作为输出。我的代码显示持续碰撞,然后崩溃...
package test;
//imports...
public class test extends SimpleApplication
implements ActionListener,PhysicsTickListener{
private MotionPath path;
private MotionPath path2;
private MotionTrack motionTrack;
private MotionTrack motionTrack2;
private AnimChannel channel2;
private AnimControl control2;
private AnimControl control3;
private AnimChannel channel3;
private BulletAppState bulletAppState;
private RigidBodyControl landscape;
private CharacterControl player;
private Vector3f walkDirection = new Vector3f();
private boolean left = false, right = false, up = false, down = false;
private TerrainQuad terrain;
private Material mat_terrain;
private GhostControl ghost;
static test app;
Material matMarker;
public static void main(String[] args) {
app = new test();
app.start();
}
float displacement=60;
int score = 0;
int robotHealth=0;
Geometry mark;
Node shootables;
Node pickUpObject1;
BitmapText hudText;
@Override
public void simpleInitApp() {
createScene();
enemies();
pickUptype1();
initCrossHairs(); // a "+" in the middle of the screen to help aiming
initKeys(); // load custom key mappings
initMark(); // a red sphere to mark the hit
hudText = new BitmapText(guiFont, false);
hudText.setSize(guiFont.getCharSet().getRenderedSize()); // font size
hudText.setColor(ColorRGBA.Red); // font color
hudText.setLocalTranslation(600, 700, 0); // position
guiNode.attachChild(hudText);
DirectionalLight sun2 = new DirectionalLight();
sun2.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f));
int width = settings.getWidth(); //width is the width of the gui
int height = settings.getHeight(); //height is the height of the gui
}
protected Geometry makeCube(String name, float x, float y, float z) {
Box box = new Box(new Vector3f(x, y, z), 3f, 3f, 3f);
Geometry cube = new Geometry(name, box);
Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
Texture tex_ml = assetManager.loadTexture("Interface/Logo/Monkey.jpg");
mat1.setTexture("ColorMap", tex_ml);
cube.setMaterial(mat1);
return cube;
}
private PhysicsSpace getPhysicsSpace() {
return bulletAppState.getPhysicsSpace();
}
/**
* This is the main event loop--walking happens here.
* We check in which direction the player is walking by interpreting
* the camera direction forward (camDir) and to the side (camLeft).
* The setWalkDirection() command is what lets a physics-controlled player walk.
* We also make sure here that the camera moves with player.
*/
@Override
public void simpleUpdate(float tpf) {
hudText.setText("SCORE \n" + " " + score);// the text
Vector3f camDir = cam.getDirection().clone().multLocal(0.6f);
Vector3f camLeft = cam.getLeft().clone().multLocal(0.4f);
walkDirection.set(0, 0, 0);
if (left) { walkDirection.addLocal(camLeft); }
if (right) { walkDirection.addLocal(camLeft.negate()); }
if (up) { walkDirection.addLocal(camDir); }
if (down) { walkDirection.addLocal(camDir.negate()); }
player.setWalkDirection(walkDirection);
cam.setLocation(player.getPhysicsLocation());
path.setCycle(true); // Make path a complete circuit
path2.setCycle(true);
motionTrack.setLoopMode(LoopMode.Loop);
motionTrack2.setLoopMode(LoopMode.Loop);
}
public Node robot(){
Node monster = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
monster.scale(1.5f, 1.5f, 1.5f);
monster.rotate(0.0f, -3.0f, 0.0f);
// Create a appropriate physical shape for it
return monster;
}
public void createScene(){
/** Set up Physics */
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
//bulletAppState.getPhysicsSpace().enableDebug(assetManager);
flyCam.setMoveSpeed(100);
setUpKeys();
terrain = new TerrainQuad("my terrain", 65, 513, heightmap.getHeightMap());
/** 6. Add physics: */
// We set up collision detection for the scene by creating a
// compound collision shape and a static RigidBodyControl with mass zero.*/
CollisionShape terrainShape =
CollisionShapeFactory.createMeshShape((Node) terrain);
landscape = new RigidBodyControl(terrainShape, 0);
terrain.addControl(landscape);
CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1);
player = new CharacterControl(capsuleShape, 0.05f);
player.setJumpSpeed(20);
player.setFallSpeed(30);
player.setGravity(30);
player.setPhysicsLocation(new Vector3f(145f, -28f, 10f));
player.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_01);
player.addCollideWithGroup(PhysicsCollisionObject.COLLISION_GROUP_01);
setUpLight();
rootNode.attachChild(SkyFactory.createSky( assetManager,
"Textures/Sky/Bright/BrightSky.dds", false));
}
public void enemies(){
shootables = new Node("Shootables");
rootNode.attachChild(shootables);
Node Robot1 = robot();
Node Robot2 = robot();
CapsuleCollisionShape capsule = new CapsuleCollisionShape(4f, 10f);
RigidBodyControl robot1Cap = new RigidBodyControl(capsule, 0.01f);
Robot1.addControl(robot1Cap);
getPhysicsSpace().add(robot1Cap);
bulletAppState.getPhysicsSpace().add(robot1Cap);
bulletAppState.getPhysicsSpace().enableDebug(assetManager);
robot1Cap.setMass(100f);
robot1Cap.setKinematic(true);
CapsuleCollisionShape capsule2 = new CapsuleCollisionShape(4f, 10f);
RigidBodyControl robot2Cap = new RigidBodyControl(capsule, 0.01f);
Robot2.addControl(robot2Cap);
getPhysicsSpace().add(robot2Cap);
bulletAppState.getPhysicsSpace().add(robot2Cap);
bulletAppState.getPhysicsSpace().enableDebug(assetManager);
robot2Cap.setMass(100f);
robot2Cap.setKinematic(true);
ghost = new GhostControl(
new BoxCollisionShape(new Vector3f(8f,8f,8f))); // a box-shaped ghost
Robot1.addControl(ghost);
ghost.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_01);
ghost.setCollideWithGroups(PhysicsCollisionObject.COLLISION_GROUP_01);
getPhysicsSpace().add(ghost);
getPhysicsSpace().addTickListener(this);
control2 = Robot1.getControl(AnimControl.class);
channel2 = control2.createChannel();
channel2.setAnim("Walk");
control3 = Robot2.getControl(AnimControl.class);
channel3 = control3.createChannel();
channel3.setAnim("Walk");
path = new MotionPath();
path.addWayPoint(new Vector3f(500f,-83f,3f));
path.addWayPoint(new Vector3f(350f,-79f, 3f));
path.enableDebugShape(assetManager,rootNode);
// Initialize our motionTrack object
motionTrack = new MotionTrack(Robot1, path);
motionTrack.setDirectionType(MotionTrack.Direction.Path);
// Enable the motionTrack
motionTrack.setEnabled(true);
path2 = new MotionPath();
path2.addWayPoint(new Vector3f(180f,-50f,-100f));
path2.addWayPoint(new Vector3f(200f, -55f, -30f));
path2.enableDebugShape(assetManager,rootNode);
// Initialize our motionTrack object
motionTrack2 = new MotionTrack(Robot2, path2);
motionTrack2.setDirectionType(MotionTrack.Direction.Path);
// Enable the motionTrack
motionTrack2.setEnabled(true);
shootables.attachChild(Robot1);
shootables.attachChild(Robot2);
}
public void physicsTick(PhysicsSpace space, float f) {
if (ghost.getOverlappingObjects().size() > 0) {
final Vector3f bPoint = ghost.getPhysicsLocation();
try {
app.enqueue(new Callable<Boolean>() {
public Boolean call() throws Exception {
app.addMarker(bPoint);
return true;
}
});
} catch (Exception ex) {
}
}
}
public void pickUptype1(){
pickUpObject1 = new Node("pickUpObject1");
rootNode.attachChild(pickUpObject1);
Node cube1 = new Node();
cube1.attachChild(makeCube("the Deputy", 220f, -63f, -150f));
Node cube2 = new Node();
cube2.attachChild(makeCube("the Deputy2", 410f, -89f, -270f));
RigidBodyControl floor_phy = new RigidBodyControl(0.0f);
cube1.addControl(floor_phy);
RigidBodyControl floor_phy2 = new RigidBodyControl(0.0f);
cube2.addControl(floor_phy2);
bulletAppState.getPhysicsSpace().add(floor_phy);
bulletAppState.getPhysicsSpace().add(floor_phy2);
pickUpObject1.attachChild(cube1);
pickUpObject1.attachChild(cube2);
}
}
最佳答案
您包含了许多不必要的代码,并且从您总体上不熟悉编程的风格来看,我编辑了您的问题以使其具有可读性,以便人们可以尝试并提供帮助(虽然没有修复缩进,但这会花费太多的耐心. 代码应该被剥离,只包括物理代码、成员变量和上下文设置。如果你的幽灵控件没有放在地面上,它会掉下来离开你的机器人,所以它会不断地与你的机器人发生碰撞地面或在最初穿过地面后穿过虚空坠落。
您应该使用 getOverlappingObjects() 来获取它与之碰撞的对象列表,然后检查该列表以获取物理空间中的字符表示。
这下面也是不好的形式。如果你的方法要抛出一个异常,你应该知道它可以抛出什么,抛出那些确切的异常并处理每个异常。否则,你基本上是穿上防弹衣,闭着眼睛跑来跑去,因为相信你不会受伤。
public Boolean call() throws Exception
/*
* adds an enemy and returns a reference to that enemy
*/
Spatial addEnemy()
{
//Characters are spatials typically in JMonkey
Spatial enemy=new Spatial();
CapsuleCollisionShape collisionShape=new CapsuleCollisionShape(4.0f, 10.0f);
CharacterControl characterControl = new CharacterControl(collisionShape, stepHeight);
enemy.addControl(characterControl);
getPhysicsSpaceState(characterControl);
shootables.attachChild(enemy);
}
CharacterControl
//to send keyboard input to the character controller to move it
KeyboardControl
GunControl
CharacterControl
//does path planning to get a route and steers character control along it
RouteController
GunControl
//AI to determine where/if I want to walk, what to shoot at, where to aim
BehaviourControl
关于java - Jmonkey 碰撞检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13103753/
我是 Jmonkey 编程的新手,我想问一个关于碰撞交互的问题,因为我的代码似乎从地形中找到了可能的碰撞,我不知道如何解决这个问题。我的目标是玩家作为第一个被检测到的人,如果他与敌人的幽灵控制相撞以显
如何朝十字准线指向的方向拍摄? 使用 JMonkey 引擎,我正在创建一个游戏,我需要一艘船来射击其他船。 因此,我创建了可以根据用户输入在屏幕上移动(上、下、左、右)的十字准线,以便用户可以瞄准某个
本周第一次开始使用 jMonkeyEngine SDK,我有点陷入了困境。我继承了别人的代码,但我正在努力让它在他们的机器上运行(他们也休假了几周,所以失去了联系)。 问题是当我尝试运行代码时,我收到
这是我的代码,用于加载带有模型的节点,然后附加动画控件。我收到 NullPointerException 因为它说我的 AnimControl 为 null。 我的动画控制类位于 Models/sti
我在 JME (JMonkey) 中遇到旋转然后平移两个框的问题。我搜索了论坛并发现了其他语言的一些类似问题,但我不明白答案,这可能是因为我不懂其他语言。我有两个带有 .lookat( [the ot
在 jmonkey 中,我看到了他们的第一个教程,出于好奇,它正在通过鼠标移动移动一个盒子,至于玩这个新玩具,我尝试使用鼠标移动来移动球体。由于功能几乎相同,我用 Sphere 替换了 Box。 pu
我正在学习 JMonkey,目的是在它的基础上构建一个框架。 如何管理资源缓存? 有什么办法可以清除吗? 有什么方法可以从缓存中删除特定项目吗? 我一直在查看应用程序对象中的 assetMaager
我正在将 jMonkey 教程翻译为 JRuby,目前位于 8th初学者。但是当我运行它时,它一直提示没有定义 settings 方法或局部变量。 settings 应该是实例变量、方法还是什么? 编
这是 JME3 教程中 HelloPhysics 的一个非常简单的扩展。当您点击一 block 砖 block 时,该砖 block 就会从游戏和物理空间中移除。如果你移走砖 block 的速度足够快
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 8 年前。 Improve this qu
有没有办法检测用户是否停止滑动?也许 bij 鼠标输入检查之类的。我尝试在 onSliderChange 事件中使用鼠标 isButton0Release 和 hasFocus 来检查用户是否停止滑动
通常情况下,鼠标被锁定在窗口上并且不可见;以第一人称射击游戏的风格控制相机。 我的理解是您从 JMonkey 窗口解锁鼠标并通过调用使其可见 inputManager.setCursorVisible
我正在尝试在使用 JMonkey Engine 3D 图形库指定的 3D 顶点之间绘制直线。 JMonkey 当然针对导入模型进行了优化,但我知道它也可以用于“内部”创建自定义形状。 例如,如果我要尝
我正在编写一个应该显示 3D 点云的程序。为此,我正在使用 jMonkeyEngine。不幸的是,我不喜欢 jMonkey 的默认相机行为。尤其是鼠标拖动和鼠标滚轮并没有真正按照我的意愿行事。我想要的
我想编辑默认 JMonkey 项目的启动屏幕,以便用自定义图像(我们的项目 Logo )替换显示 JMonkey 的图像。我指的是执行 SimpleApplication 项目时出现的屏幕。我在 Li
我已经开始学习使用jMonkey引擎进行游戏开发。我能够使用 TerrainQuad 创建单个地形图 block ,但下一步我坚持使其无限。我已经浏览了 wiki 并想使用 TerrainGrid 类
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,
我已经翻译并使用了初学者 #5 之前的所有教程,但我对 Java 的了解还不够深,不知道如何移植这些行: private ActionListener actionListener = new Act
我最近了解到 jMonkey 仅在一个线程上运行,即它的 openGL 渲染线程。但是我无法完全理解它。我可以理解它在单个更新循环中执行所有更新和初始化()调用,但输入应该独立于此更新循环,否则它将成
在 JME3 中,当从图像加载纹理时,它会将其拉伸(stretch)到我放置它的四边形的大小。但它也模糊了它,我不想要这个(我正在制作 Minecraft 风格的图形),所以我怎么能阻止它呢? 此外,
我是一名优秀的程序员,十分优秀!