sahar lando
sahar lando

Reputation: 21

Python turtle set direction of a turtle to another turtle

I am using python 3.6 and turtle module. I have two turtles in another coordinates. how do i set the angle of turtle_1 to the direction of turtle_2?

Upvotes: 1

Views: 1441

Answers (1)

cdlane
cdlane

Reputation: 41872

turtle_1.setheading(turtle_1.towards(turtle_2))

This is typically used if you want turtle_1 to chase turtle_2. The argument to towards() is flexible. Besides another turtle, it can also be separate X and Y arguments, or a tuple coordinate pair. If you simply want turtle_1 to point in the same direction as turtle_2:

turtle_1.setheading(turtle_2.heading())

Upvotes: 3

Related Questions