# Look at func browsing

• posted
0

π¬π΄ i dont know if its the lack of sleep or increased stress... but i have completely forgoten how to write a LookAt function... can anyone give me hand?

Im trying to get Object A to look at Object B

• posted
0

This might not be the best way but it seems to work..

``````
def LookAt(pos1, pos2):
dx, dy = pos1[0]-pos2[0], pos1[1]-pos2[1]
angle = math.degrees(math.atan2(float(dy), float(dx)))
angle += 90
if angle < 0:
angle += 360
print(angle)
return angle
``````

the `+90` is so 0 is north (screen.w/2, screen.h)

otherwise 0/360 is left center

• posted
0

@njm

@ccc it shows i had a reply that mention myself from @njm but theres nothing on the post.. is this a common bug?

• posted
0

@stephen said:

but theres nothing on the post

I've already posted something, then deleted, then purged but I don't know how other see it.

• posted
0

@cvp said:

@stephen said:

but theres nothing on the post

I've already posted something, then deleted, then purged but I don't know how other see it.

only post and Notification i get if for this one βͺβͺβͺ where i still have notification from the @njm even if the post was deleted lol π§ i just get anxious when random buts happen lol especially if i cant hunt it down myself πΆπ€ͺπ

• posted
1

@stephen, I always keep a vector class ready. I have it in many places, at least in scripter:

``````from scripter import Vector
import scene

pos1 = scene.Point(100, 100)
pos2 = (50, -20)
vector1 = Vector(pos1)
vector2 = Vector(pos2)

delta = vector1 - vector2 # vector from pos2 to pos1
print('Degrees:', delta.degrees)
print('Distance:', delta.magnitude)

# Move pos1 twice as far away from pos2
# and rotate using pos2 as origo

delta *= 2
delta.degrees += 10

print('New pos1:', vector2 + delta)
``````

• posted
0

@mikael Awesome! thank you

• posted
0

@stephen, I replied and then realized I hadn't read your post fully. I then deleted and purged it. Sorry for the confusion. I would code it the some way you did. I do like @mikael 's method, very pythonic. Many thanks to both of you for supporting this wonderful app.

• posted
0

@njm said:

@stephen, I replied and then realized I hadn't read your post fully. I then deleted and purged it. Sorry for the confusion. I would code it the some way you did. I do like @mikael 's method, very pythonic. Many thanks to both of you for supporting this wonderful app.

Awesome thank you for clearing that up! and same to you!

Internal error.

Oops! Looks like something went wrong!