How to have an actor follow another actor with rotation?

billpaternobillpaterno Member Posts: 26
edited November -1 in Working with GS (Mac)
I followed the tutorial on how to get one actor to follow another. It works great! However, I want to add rotation to the mix. There tutorial does not mention how to follow rotation except that "A more complicated math function would be needed if the actor rotates."

Could anyone give me more insight on the math involved? Right now I have a main actor with another actor following it. The following actor emits particles. I want the particles to look as if they are emitting from the back end of the main actor so I had to offset the X position Constrain Attribute. This looks fine going side to side, but when my main actor rotates, the emitter no longer is directly behind the main actor. I am guessing if I can have it rotate as well, that would fix the problem.

Any help would be greatly appreciated.

Thanks,
billpa

Comments

  • EastboundEastbound Member, BASIC Posts: 1,074
    I believe it would use arctan. I'll look into when I get home, as I need it for an engine, too.
  • billpaternobillpaterno Member Posts: 26
    Thanks!
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    Is there a spot in the wiki with an explanation of all the math abbreviations (those weird things I see when I go to select "random" - that's the only one I have any clue about). :-P

    It would be awesome if these were explained in the wiki WITH AN EXAMPLE!
  • EastboundEastbound Member, BASIC Posts: 1,074
    Well without some geometry or more advanced maths they aren't really uselful to you. They're used commonly in advanced maths. Wikipedia them if you really want to learn them
  • firemaplegamesfiremaplegames Member Posts: 3,211
    I can help you with some of the easier ones...

    RANDOM
    Very handy, gives you a random number between two numbers that you specify, i.e "Please give me a random number between 2 and 13."

    FLOOR
    This rounds a number DOWN to the nearest integer. i.e, floor(4.5) will round it down to 4, or floor(1.984375347389475) will round it down to 1

    CEIL
    The opposite of floor. Will round a number UP to the nearest integer. i.e, 4.3 becomes 5, and 1.000001 becomes 2

    GameSalad doesn't seem to have just a ROUND math function, which would round a number up or down, i.e 4.3 becomes 4 and 4.9 becomes 5. I'm not sure why it isn't included, although computers do have rounding errors, which can cause havoc.

    ABS
    Short for Absolute. This always returns a positive number. i'm not a math major, but it sort of works like this:
    abs(-5) will give you the answer: 5. as will abs(5)... they both give you the "distance" that number is from 0.
    In this case, both 5 and -5 are 5 units away from 0. does that make sense?
    abs is very handy for always returning a positive number, especially when subtracting 2 numbers. it is used all the time in this situation:

    I need to find out how far I travelled on the x axis from my starting location. So the math formula for that is: (currentX - initialX) This will give me the distance I travelled. However, I could have travelled to the LEFT or RIGHT from my starting X. and if i subtract them like that, going to the left will give me a negative number. i want the distance to always be positive. so i use abs like this: abs(currentX - initX)

    MAX
    This returns the greater of two values. it is used like this max(6,3) will return 6. Or in this case:max(player1Score, Player2Score) whichever is higher. very useful for comparing two numbers.

    MIN
    The opposite of max. returns the lower number.

    Those are the easier ones, the other ones require geometry and trigonometry.
    But those are very useful as well, especially in games where you use angles, trajectories, etc.

    Someone smarter than me should explain them though!

    Hope this helps!
    Joe
  • EastboundEastbound Member, BASIC Posts: 1,074
    I believe I found it. You would simply constrain your following object's rotation to:

    vectorToAngle( self.Position.X - game.PlayerX , self.Position.Y - game.PlayerY )

    Note: PlayerX and PlayerY would be the names of the global attributes containing your player's position.
  • billpaternobillpaterno Member Posts: 26
    thanks! I will try this out later tonight.
  • EastboundEastbound Member, BASIC Posts: 1,074
    I used it in my game and it works! ;)
  • TraXsiv2TraXsiv2 Member Posts: 29
    Hey, I tried using
    Eastbound said:
    I believe I found it. You would simply constrain your following object's rotation to:

    vectorToAngle( self.Position.X - game.PlayerX , self.Position.Y - game.PlayerY )

    Note: PlayerX and PlayerY would be the names of the global attributes containing your player's position.

    When I play the game it freezes
  • firemaplegamesfiremaplegames Member Posts: 3,211
    make sure you select those attributes from the drop down list, you cannot type them in.
  • chosenonestudioschosenonestudios Member Posts: 1,714
    TraXsiv2 said:
    Hey, I tried using

    When I play the game it freezes

    You have a syntax error
  • ORBZORBZ Member Posts: 1,304
    PROTIP:

    To always point your actor forward no matter which way he's heading, for any moving actor:

    constrain attribute: self.rotation = vectorToAngle(self.linearVelocityX, self.linearVelocityY)
  • aandiaandi Member Posts: 99
    how do you create an global attribute
  • aandiaandi Member Posts: 99
    what do i type in because it is not global attribute
  • aandiaandi Member Posts: 99
    oh .. ok thank you
  • aandiaandi Member Posts: 99
    might sound like a daft question but i am following this

    vectorToAngle( self.Position.X - game.PlayerX , self.Position.Y - game.PlayerY )

    and when i get to the player x what do i do. if the global attribute is player x or player y
  • aandiaandi Member Posts: 99
    ok i get it now. but it it staying in place an that is verticle
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    In the expression editor, use the drop-down menu on the left:
    Click 'game'.
    Then double-click on 'player x'.
  • aandiaandi Member Posts: 99
    no i get that. but it doesn't rotate when my other actor rotates.
  • aandiaandi Member Posts: 99
    bump
  • aandiaandi Member Posts: 99
    please help
  • aandiaandi Member Posts: 99
    please help someone
  • aandiaandi Member Posts: 99
    any ideas
  • aandiaandi Member Posts: 99
    please help
  • aandiaandi Member Posts: 99
    ok, please may you help
  • aandiaandi Member Posts: 99
    please can someone help
  • kirklandkirkland Removed Posts: 268
    can anybody help
  • kirklandkirkland Removed Posts: 268
    this is nothing to do with my game :)
Sign In or Register to comment.