Rotation to face an actor

TraXsiv2TraXsiv2 Member Posts: 29
edited November -1 in Working with GS (Mac)
Hello, In my game I have these stationary turrets that I want rotate to face the player actor at all times. I'm having trouble figuring this out. Thanks

Comments

  • quantumsheepquantumsheep Member Posts: 8,188
    Keep a track of the player's X and Y coordinates by constraining player self.positionx to a variable called 'playerX' and player self.positiony to a variable called 'playerY'.

    Then, on your turrets, put in the behaviour rotate to

    and in the X and Y fields, hit the little 'e' button next to it and make the X field 'playerX' and the Y field 'playerY'.

    Hope that makes sense,

    QS :D

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • TraXsiv2TraXsiv2 Member Posts: 29
    Do I use "rotate to position" for the turrets and if so what do i put in for the offset Angle.

    Thanks for you help
  • TraXsiv2TraXsiv2 Member Posts: 29
    Yeah, I am having trouble setting it up.

    So far I have two GAME attributes which are playerX and playerY. they are set to 0 and both are integers
    In my player's actor I have two "Constrain Attributes" self.Postion.X To PlayerX and self.Position.Y To PlayerY

    As far as what goes into the turrets I am confused how to set everything up.
  • firemaplegamesfiremaplegames Member Posts: 3,211
    I'm not sure about the rest, but you will need to switch those attributes...

    game.playerX to: self.position.x
    game.playerY to: self.position.y
  • ORBZORBZ Member Posts: 1,304
    Rotate to position: playerX, playerY

    Offset angle: 0

    Do the switch as FMG said.
  • TraXsiv2TraXsiv2 Member Posts: 29
    I got it working guys. Thank you so much. I had to put a timer in on both the turret and the player so that it would constantly check the attributes.
  • ORBZORBZ Member Posts: 1,304
    @TraXsiv2

    Your method is cpu intensive and won't work for large projects with lots of turrets. Timers eat cpu.

    Trust us, you don't need a timer. You need to use constraints.
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    a constraint constantly checks and changes whatever is being constrained. So if you are constraining the rotation of something to something else using VectorToAngle it is constantly checking the angle and then changing the rotation to that angle. Therefore constraints are also cpu intensive but should be a lot smoother looking than a timer system and probably less cpu intensive than a timer. Use both timers and constrains sparingly.
  • ORBZORBZ Member Posts: 1,304
    ^^^ what he said ;)
Sign In or Register to comment.