# explination on this code pls..

if (self.keyMap[“forward”]!=0):
backward = self.ralph.getNetTransform().getMat().getRow3(1)
backward.setZ(0)
backward.normalize()
self.ralph.setPos(self.ralph.getPos() - backward*(elapsed*5))

can some one explain briefly what this set of code is doing… im totally new to panda, python and programming in general… thxs in advance…

You don’t need to understand this IMHO, the Roaming Ralph sample does it wayy too complicated.
The correct and simpler way to do it is:

``````if (self.keyMap["forward"]!=0):
self.ralph.setY(self.ralph, elapsed*5)``````

This basically moves ralph over a distance of ‘elapsed*5’ over his own Y axis (meaning forward)

It’s not necessary for roaming ralph but for some specific circumstances that code comes in handy, for example if you have a node and you’re interested its direction vector without the pitch.

``backward = self.ralph.getNetTransform().getMat().getRow3(1)``

getNetTransform().getMat() returns the total transformation of a node as a matrix. getRow3(1) returns the Y axis of the transformation matrix as a vector.

``backward.setZ(0)``

This ‘flattens’ the vector on the Z axis so that the vector is only applicable to the XY axis

``````backward.normalize()
self.ralph.setPos(self.ralph.getPos() - backward*(elapsed*5)) ``````

The normalize() method sets the length of the vector to 1. This vector is then applied to the position of ralph along with the delta time.