Forum Archive

Look at func

stephen

😬😴 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

stephen

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

stephen

@njm

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

fwd: @JonB @mikael @cvp @omz

post screen sho

cvp

@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.

stephen

@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 😢πŸ€ͺ😜

mikael

@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('Radians:', delta.radians)
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)
stephen

@mikael Awesome! thank you

njm

@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.

stephen

@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!