How to detect when rotated to position

RocketBrainRocketBrain Member, PRO Posts: 269

I can get my actor to rotate to the position

I need to know how to detect that its completed it so i can tell the actor to do the next behavior

aka tank rotates to target, then moves.

Comments

  • SocksSocks London, UK.Member Posts: 12,822

    when self rotation%360 = vectorToAngle(targetX-selfX,targetY-selfY)%360 . . . .

  • RocketBrainRocketBrain Member, PRO Posts: 269

    %360?

  • SocksSocks London, UK.Member Posts: 12,822

    @RocketBrain said:
    %360?

  • RocketBrainRocketBrain Member, PRO Posts: 269
    edited March 2016

    i got it so

    Change MyAngle = VectortoAngle(targetX-pos.x, targetY-pos.y)

    rotate to position x, y

    when self.rotation = MyAngle
    then move

  • SocksSocks London, UK.Member Posts: 12,822

    @RocketBrain said:
    i got it so

    Change MyAngle = VectortoAngle(targetX-pos.x, targetY-pos.y)

    rotate to position x, y

    when self.rotation = MyAngle
    then move

    Setting it up like that will likely cause you issues (rotation and V2A work on different value ranges), also there's no real need to introduce another attribute ('MyAngle'), it doesn't seem to serve any obvious purpose.

  • RocketBrainRocketBrain Member, PRO Posts: 269

    you're really confusing me man. ok so can you break it down for a simpleton like me? it worked once my way and then didn't which was weird.

    whats the %360??? you posted a diagram of owl parts...

  • RocketBrainRocketBrain Member, PRO Posts: 269

    you're right. made it simpler but its only working if the target is above the original. if the target is below it. it doesn't.

  • RocketBrainRocketBrain Member, PRO Posts: 269

    and nevermind lol got it. sets maximum angle at 360 so it doesn't get confused?

  • SocksSocks London, UK.Member Posts: 12,822
    edited March 2016

    @RocketBrain said:
    you're really confusing me man.

    :) Sorry ! You asked a question and I gave you an answer, you then suggested an alternative way (your post starting "i got it so . . . ") and I replied that setting it up like that will likely cause you issues . . . hope that makes sense now.

    @RocketBrain said:
    ok so can you break it down for a simpleton like me? it worked once my way and then didn't which was weird.

    Yep, like I say, setting it up like that will likely cause you issues as V2A and Rotation work on different value ranges. For example I'm going to guess that the time it worked the target's Y value was above the player ?

    @RocketBrain said:
    whats the %360??? you posted a diagram of owl parts...

    I didn't know what your question was, I'm not very good with vague questions, you'd simply taken a part of my suggested equation and reposted it, it could have meant numerous things, so I thought the best thing to do would be to post a picture of an owl.

  • SocksSocks London, UK.Member Posts: 12,822

    P.S

    %360 forces both Rotation and V2A into using the same 0-360 value range.

  • SocksSocks London, UK.Member Posts: 12,822
    edited March 2016

    @RocketBrain said:
    you're right. made it simpler but its only working if the target is above the original. if the target is below it. it doesn't.

    Your version will display this problem, the version I suggested won't, like I've said, setting it up the way you suggest will cause you issues, this is one of those issues.

    At least give this a try:

    when self rotation%360 = vectorToAngle(targetX-selfX,targetY-selfY)%360

  • SocksSocks London, UK.Member Posts: 12,822
    edited March 2016

    //

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    @Socks I thought you posted an owl because they can turn their heads 360°.

    @RocketBrain The %360 is the mod() function which returns the remainder of a division problem. It can also be written mod(self.rotation,360). So if you had values larger than 360, it would constrain the result as @Socks said above. For example:

    330%360 = 330
    375%360 = 15
    720%360 = 0
    800%360 = 80

    You can use Spotlight on a Mac to check the value of mod(). Type in "330%360" (without quotes) to see what I mean.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • RocketBrainRocketBrain Member, PRO Posts: 269
    edited March 2016

    @Socks thanks for the help although i still don't get the owl lol

    @tatiang thanks for the detailed explanation of %360, i hadn't seen that used before

    I did end up getting it to work. I actually asked this question two more times over the last six years and nobody could help.

    You guys are great :smile:

Sign In or Register to comment.