Rotate Texture in function of player position

前端 未结 2 1865
北恋
北恋 2021-01-28 10:14

I\'m making a 2d game that consists in a plane fighting against spaceships trough missiles, i want the spaceships to rotate in function of the player position, so that they are

2条回答
  •  难免孤独
    2021-01-28 10:37

    I think this should work. Set..

    v = centerPosOfShip - centerPosOfUFO
    

    Normalize...

    v /= sqrt( v.x * v.x + v.y * v.y )
    

    So now we can say v = [ cos(theta) sin(theta) ]; the rotation matrix is...

    [ cos(theta)  -sin(theta) ]
    [ sin(theta)   cos(theta) ]
    

    So we can write in terms of v-components...

    [ v.x  -v.y    centerPosOfUFO.x ][x]
    [ v.y   v.x    centerPosOfUFO.y ][y]
    [ 0     0      1                ][1]
    

    where [x y] is any point on the UFO relative to its center.

    Hope that makes sense

提交回复
热议问题