Constrain the angle of the canon towards the player

BigDaveBigDave Member Posts: 2,239

I guess you guys have a quick answer for this.

I want a canon that always points towards the player position. So I can place multiple canon's at different locations that all point to the player.

I constraint the X and Y of the Player as global game variables.

Within the canon actor code I did
(vectorToAngle( game.PlaneX , game.PlaneY ))

So I got the angle for the Player.
So now I have to figure how to get the coordinations of both compared so when I move my player it checks the difference between this two actor types.

How exactly would that work?

Comments

  • HopscotchHopscotch Member, PRO Posts: 2,782

    @BigDave, vectorToAngle takes the difference between Tower and player position.

    So you need to do

    vectorToAngle(self.Position.X-game.PlaneX,self.Position.Y-game.PlaneY)

    then rotate the tower to that angle.

  • BigDaveBigDave Member Posts: 2,239
    edited May 2014

    @Hopscotch Thanks man! Let's try it.

  • BigDaveBigDave Member Posts: 2,239

    @Hopscotch‌
    Hat to add the start angle behind but else it worked perfectly!
    vectorToAngle(self.Position.X-game.PlaneX,self.Position.Y-game.PlaneY)-90

    Thanks again. This thread is answered.

  • SocksSocks London, UK.Member Posts: 12,822
    edited May 2014

    @BigDave said:
    Hopscotch‌
    Hat to add the start angle behind but else it worked perfectly!
    vectorToAngle(self.Position.X-game.PlaneX,self.Position.Y-game.PlaneY)-90

    Thanks again. This thread is answered.

    You can also do this with the Rotate To behaviour . . . .

  • BigDaveBigDave Member Posts: 2,239

    @socks
    haha wtf thats awesome!

Sign In or Register to comment.