# problems with rotation

hi,
I am making a game in which you are in a bunker - position (0,0,0) and enemies are attacking you. their position is random - of course limited so they can apper randomly within certain area.

I need them to to turn so they are facing the bunker ( how they find out which angle is right ?) and then they begin to move in right direction to bunker.

So they always move facing forwards:

``````
def moveForward(actor):
dist = 2
angle = actor.getH()*math.pi/180.0
dx = dist*math.sin(angle)
dy = dist*-math.cos(angle)
movement = actor.posInterval(0.1,Vec3(actor.getX()+dx,actor.getY()+dy,0))
movement.start()``````

turns:

``````
def turn(dir):
dist = 2
angle = actor.getH()*math.pi/180.0
dx = dist*math.sin(angle)
dy = dist*-math.cos(angle)

movement = actor.hprInterval(0.2,Vec3(actor.ship.getH()-(10*dir),0,0))
)
movement.start()``````

to set their initial facing:

``````
actor.setHpr(vec3(0,0,0))``````

great, thanks ! I have always found the NodePath’s lookAt() function to be extremely helpful. You can pass in a point in space, or another nodepath as the argument, and it will turn to face that point or other nodepath.

``````first = render.attachNewNode("first")
second = render.attachNewNode("second")
second.setPos(20,30,75)
first.lookAt(second)``````