Animate in Direction of Motion

Matter91Matter91 Member Posts: 7
edited November -1 in Working with GS (Mac)
Ok, so in my game actors are randomly spawned from right, left and bottom towards and travel to a point at the top center of the screen. Your goal is to stop them by dropping bombs with the click of a mouse.

The problem I have is that the actors all face the same direction no matter where they are spawned and where they are headed. I need them to face in the direction they are moving.

Is there any way to do this without creating multiple actors or multiple spawners?

Comments

  • Matter91Matter91 Member Posts: 7
    Matter91 said:
    Ok, so in my game actors are randomly spawned from right, left and bottom towards and travel to a point at the top center of the screen. Your goal is to stop them by dropping bombs with the click of a mouse.

    The problem I have is that the actors all face the same direction no matter where they are spawned and where they are headed. I need them to face in the direction they are moving.

    Is there any way to do this without creating multiple actors or multiple spawners?

  • DrGlickertDrGlickert Member Posts: 1,135
    When you put your image into the actor have that image facing to the RIGHT.

    Then, do a behavior on the actor that will change the rotation of the projectile (or enemy or whatever it is that's spawning).

    Let me know if you have any more problems and I'll help you out as best I can.

    Good luck!
  • Rob2Rob2 Member Posts: 2,402
    This should do it

    image
  • Matter91Matter91 Member Posts: 7
    Thanks, so I put the image in facing to the RIGHT, and I put a change attribute behavior- self.rotation, but I'm not sure what I am supposed to change it to.

    The angle of the actor should be different based on where it is being spawned from (left, right, bottom).
  • DrGlickertDrGlickert Member Posts: 1,135
    I would suggest that if the projectiles or enemies or whatever do not change direction then I would just have a Change Attribute instead of a constrain attribute (only because of processing and memory management). But if they fly around then you'll want to use a constrain.
  • Matter91Matter91 Member Posts: 7
    I just tried a constrain attribute self.rotation to vectorToAngle(self.Motion.Linear Velocity.X,self.Motion.Linear Velocity.X)

    and I tried the change attribute and interpolate (on a hunch),
    my actors still travel toward the point facing while facing the right.

    Is there any way to use the position of the object they are traveling towards maybe?
  • warpserwarpser Member Posts: 10
    Scene variables: endPointX, endPointY (Top center)

    Constrain:
    self.Rotation
    TO
    vectorToAngle(game.endPointX-self.Position.X,game.endPointY-self.Position.Y)
  • Matter91Matter91 Member Posts: 7
    I don't see endPoint under game, am I suppose to create an attribute?

    I have my actors moving by setting them to interpolate their position.X to 360 and their position.Y to 460. Is this where the conflict is? Perhaps using some different logic to have them move to the object I want them to move to?
  • warpserwarpser Member Posts: 10
    Try:

    Constrain:
    self.Rotation
    TO
    vectorToAngle(360-self.Position.X,460-self.Position.Y)
  • Matter91Matter91 Member Posts: 7
    Halleluiah!!!! That worked.

    I changed the interpolate to accelerate toward on the actor for its motion,
    and set a constrain attribute, constraining self.rotation to
    vectorToAngle(self.Linear Velocity.X, self.Linear Velocity.Y)

    Thank you guys for all your help. This community here is awesome.
  • TheodiTheodi Member Posts: 96
    Hello everyone I'm new to using gamesalad, and Im stuck! Looked at the forum and online to try and work it out been at it for ages with not much luck! I have the same problem as above I think.

    I have a moving actor, it moves in direction of where the player taps, but right now it faces just one direction.

    I want it to face the direction it travels. I tried the above but i doesn't seem to work. How do I get it to face the direction it is traveling?

    Any help appreciated!
  • spliketspliket Member Posts: 93
    did you type out "vectorToAngle" or did you select it from the expression list? you have to select the expression from the expression list and the attributes (self.LinearVelocity.X) from the attributes list. you can't just type them.
  • TheodiTheodi Member Posts: 96
    spliket said:
    did you type out "vectorToAngle" or did you select it from the expression list? you have to select the expression from the expression list and the attributes (self.LinearVelocity.X) from the attributes list. you can't just type them.

    I will try this thanks! I typed it earlier so thats probably the problem.
  • TheodiTheodi Member Posts: 96
    That worked great! Thanks a lot :) By the way is it possible to submit apps to the app store on the free version of gamesalad?
  • jb15jb15 Member Posts: 602
    In answer to your last question, Theodi--Yes. GameSalad games can be made on the app store with no money going to GameSalad. You have the option of purchasing the pro version (more features), but tha'ts not necessary. What is necessary is that $99 go to Apple.
Sign In or Register to comment.