Get direction from node object

I have an object imported from ms3d.this object actually as node. i want this object have gun. I think to make gun i must attach controller to this object.But unfortunately :x  i see requirement direction to create controller. I don't meet method to get direction from node location. anyone can help me How to get direction from Node??? :x

You get get the rotation via getWorldRotation(). But if you attach the gun to the model node you won't need that. What direction do you need?


i mean,wanna make controller to point bullet. So i can control it's moving as i want. I try to extend controller like this:

package MoveController;

import com.jme.math.Vector3f;
import com.jme.scene.Controller;
import com.jme.scene.Node;
import com.jme.scene.Spatial;
import com.jme.scene.TriMesh;

public class straightMove extends Controller{
    private static final long serialVersionUID = 1L;
   /** Bullet that's moving */
    /* mover = movtimeing object
     * target = checkec object //if(!utama.isActive())
     * */
   TriMesh mover;
   Node target;
   Node rootNode;
   /** Direciton of bullet */
   Vector3f direction;

   /** speed of bullet */
   float speed = 10;

   /** Seconds it will last before going away */
   float lifeTime = 5;

   public straightMove(TriMesh mover,Node target,Vector3f direction,Node rootNode) {
      this.mover= mover;;
      this.direction = direction;      
      // TODO Auto-generated constructor stub

   public void update(float time) {
      lifeTime -= time;
      /** If life is gone, remove it */
      if (lifeTime < 0) {
      /** Move bullet */
      Vector3f bulletPos = mover.getLocalTranslation();
      bulletPos.addLocal(direction.mult(time * speed));
      /** Does the bullet intersect with target? */
      if (mover.getWorldBound().intersects(target.getWorldBound())) {                           
         lifeTime = 0;
   public void detachChild(){
   //please clear mover
   private void playSound(){
   public Spatial getMover(){
      return mover;

we can see there. There is an parameter Vector3f  as direction. This vector is got from Object(ms3d as Node).So i must have vector3f from this Object to add controller.Isn'it? That my idea. I don't know it can work or not.


i have iready try to solve it by myself.I have already realize that direction is value of angle of rotation.In my project i create direction in x,y plane. So doesn't difficult i think. I just put this code to change direction:

direction.x = FastMath.cos(getAngleRotation()+getStartAngle());
direction.y = FastMath.sin(getAngleRotation()+getStartAngle());
direction.z = 0;

you can get the direction usually that way:

Vector3f direction = node.getLocalRoataion().getRotationColumn(2);

what is the usage of 2 in .getRotationColumn(2);?

It’s the “bad” way of doing:

It’s generally done by people who either have no idea what they are doing (and copied it from somewhere) or are too clever for their own good.

1 Like