Keeping it Up Front.

belleechbelleech Member Posts: 34
edited November -1 in Working with GS (Mac)
Hi Guys

I have this actor that has to have a shield in front of it. The actor rotates 360 and I know how to constrain the shield X , Y pos relative to the actor. But the problem is, I cant seem to have the shield rotate to be always north side or in front* of the actor. When the actor and shield rotates, the shield rotates in position fixed position and looses the north pos relative to the actor. Anyone tried to crack this one?

Regards.

Comments

  • scitunesscitunes Member, Sous Chef Posts: 4,047
    the correct way probably involves trig or some other scary math function (there may be a recently added chainsaw demo game you could search for). Otherwise create an image that is mostly transparent with the shield in the top part of the image. Line it up so that when centered over the main actor it is lined up correctly. Then create a game angle attribute. Contrain the game attribute to the main player's rotation and constrain the shiled's rotation to the the game attrribute. Also constrain the shield's X and Y (with no offset because you should have already accounted for this in the image file) to the main actor's X and Y. Keep in mind that this will cause the main actor to be protected all around and not just where the visible shield is - so you may want to try to figure out the math. Good luck!
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    Here is the math way:

    Constrain the actor's Rotation attribute to a game attribute. (Assuming actor at 0 rotation faces right.)
    Also constrain the actor's position to game attributes (game.ActorX and game.ActorY).

    Constrain the position of the shield to the distance or radius(r) from the actor to
    shield's self.Position.X = r*cos(game.ActorRotation) + game.ActorX
    and
    shield's self.Position.Y = r*sin(game.ActorRotation) + game.ActorY

    and constrain the shields rotation to the actor's rotation as well.
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    cool! added this to favorites!
  • JGary321JGary321 Member Posts: 1,246
    Lol me neither, I just save them as bookmarks lol. Nice.

    How do you view your favorite posts now??
  • rebumprebump Member Posts: 1,058
    I set something similar up about a week ago in two examples for UtopianGames. The first was his "chainsaw" experiment. He wanted the chainsaw to always face outward when rotating the green circle actor:

    http://gamesalad.com/game/play/39926

    The second was CodeMonkey's dual joystick demo. UtopianGames was trying to copy my "chainsaw" fix into it to make a lightsaber always appear in front of the "jedi" actor (the four color circle in CM's demo...I couldn't resist making it into a cheaply drawn cloaked character though):

    http://gamesalad.com/game/play/40513

    The only thing you would do differently would be to constrain the shield's rotation to the main actor's (i.e. the ship) rotation to force it to always be in front. As it stands right now, in the "chainsaw" demo, the "chainsaw" orbits its actor. In the "jedi" demo, the lightsaber is controlled with the second (left/red) joystick. Just constrain, and you should be able to keep it up front.
  • belleechbelleech Member Posts: 34
    Cool, Glad to know what I need is possible. Thanks Guys. I Searched that chainsaw demo and its perfect.
Sign In or Register to comment.