How to have an actor follow another actor with rotation?
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
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
It would be awesome if these were explained in the wiki WITH AN EXAMPLE!
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
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.
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)
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
Click 'game'.
Then double-click on 'player x'.