AI Code Not Working

@javagame said: Read your code again, you are using the node's location instead of the Zombie's,

[java]zombieNode.getChild(“Zombie1”).setLocalTranslation(zombieNode.getLocalTranslation().interpolate(cam.getLocation(), tpf / distance2)); [/java]

should be

[java]zombieNode.getChild(“Zombie1”).setLocalTranslation(zombieNode.getChild(“Zombie1”).getLocalTranslation().interpolate(cam.getLocation(), tpf / distance2)); [/java]

Oh woops. Never program at 12:30 am.

It still doesn’t work though.

[java]float distance2 = zombieNode.getChild(“Zombie1”).getLocalTranslation().distance(cam.getLocation()) / 10;
zombieNode.getChild(“Zombie1”).setLocalTranslation(zombieNode.getChild(“Zombie1”).getLocalTranslation().interpolate(cam.getLocation(), tpf / distance2)); [/java]

@Connor14
Think it through, what happens when you try moving something with mass along the floor in a straight horizontal line, when there’s gravity…? Friction. So, how can you change its location then… use setPhysicsLocation on its rigidBodyControl. Is there a way to do this? Yes, check the javadocs. It’s getting the the point where I can’t help you EVERY step of the way, in order to write a game, you will need to spend some time checking through your code when you get a bug, think things through logically, and read the manuals. That doesn’t mean you can’t ask for help, just… Don’t rely on the forum too heavily, or else you will never learn anything.

EDIT: I’ve confused myself with physics… Same still applies though, There IS a way you can call setPhysicslocation on it, and its all in the javadocs. See if you can find it. I think another way to do it would be to make it a kinematic Spatial.

@javagame said: @Connor14 Think it through, what happens when you try moving something with mass along the floor in a straight horizontal line, when there's gravity.....? Friction. So, how can you change its location then... use setPhysicsLocation on its rigidBodyControl. Is there a way to do this? Yes, check the javadocs. It's getting the the point where I can't help you EVERY step of the way, in order to write a game, you will need to spend some time checking through your code when you get a bug, think things through logically, and read the manuals. That doesn't mean you can't ask for help, just... Don't rely on the forum too heavily, or else you will never learn anything.

I did that already and I asked how to get the physics for a specific child earlier in this thread.

@Connor14 said: I understand what you are saying though I'm not sure how to do it. I have a loop set up to create any number of zombie geometries (right now the zombies are cubes for testing purposes) each with a different name - Zombie1, Zombie2, Zombie3, etc. Is there a way to get the physics of a particular child in order to move it?

I know I can call zombieNode.getChild(“Zombie1”); to get and set things based on that geometry but as far as I know, there is no way to get and set the physics for that particular child.

This is what I am confused about. As I said, I had already tried using .setLocalTranslation() and I had already said that it doesn’t work because the zombies are physical objects.

If you look at my code above, the rigidBodyControl is called zombiePHY. I figured out how to move one zombie earlier using this:

[java]float distance2 = zombiePHY.getPhysicsLocation().distance(cam.getLocation()) / 10;
zombiePHY.setPhysicsLocation(zombiePHY.getPhysicsLocation().interpolate(cam.getLocation(), tpf / distance2));[/java]

What my quoted question is referring to is that I do not know how to set the physical location of a different zombie (that is named differently) that uses the same geometry and the same rigidBodyControl.

I know how to use zombieNode.getChild(“Zombie1”) but I don’t know how to access the physics of that particular child.

I appreciate all the help you have been giving me but rereading some of the previous posts would help keep us both from getting really annoyed and pissed off.

http://hub.jmonkeyengine.org/javadoc/com/jme3/scene/Spatial.html
Read the javadoc. How would you get the physics control for a spatial?

@javagame I got it working

[java]float distance = zombieNode.getChild(zombieName).getControl(RigidBodyControl.class).getPhysicsLocation().distance(cam.getLocation()) / 10;
zombieNode.getChild(zombieName).getControl(RigidBodyControl.class).setPhysicsLocation(zombieNode.getChild(zombieName).getControl(RigidBodyControl.class).getPhysicsLocation().interpolate(cam.getLocation(), tpf / distance));[/java]

Thanks for putting up with me :stuck_out_tongue:

1 Like