This site requires JavaScript, please enable it in your browser!
Greenfoot back
getreides
getreides wrote ...

2014/7/28

getDirection of vector movement doesn't work

getreides getreides

2014/7/28

#
In the framework of a szenario for which I use the SmoothMover and Vector class, I am trying to get the direction of the "private vector movement" (that is automatically generated by the system, summing up all vectors and addForce calls) by using this method:
1
2
3
4
5
6
public void getVectorDirection()
    {
      Vector vector = new Vector();
      int currentRotation = vector.getDirection();
      vectorRotation = currentRotation;
    }
However, the variable vectorRotation (declared on top of the class the method is in) remains 0 though the method is called in the act-method of the class. Does anyone know why?
danpost danpost

2014/7/28

#
Line 3 is creating a NEW Vector object (with default settings for direction and speed). You need to get a reference to the already present Vector of the object and get its direction. You should (but, this may depend on the version of SmoothMover you are using) be able to use 'getMovement().getDirection()'.
getreides getreides

2014/7/30

#
Thanks mate, I'll try this out ASAP and get back to you :-)
getreides getreides

2014/8/3

#
It does work, thanks again!
You need to login to post a reply.