How to attach arm to body?

BATMOOSEMIKE

  • Posts: 8
So, I'm making a 2d shooter game, and the main character is supposed to shoot where the mouse points. I have already completed the behavior for shooting, but I want to attach two sprites together (an arm and a body) so that I can simply make the arm rotate towards the mouse and avoid all the animation stuff. I tried using the always block to make a behavior that would do this, and it's attached below. However, I don't have the option to choose which actor I want my arm to move to.

Thanks in advance for any help!

Callan S

  • Posts: 147
IIRC you want the main actor to create the arm. Make the arm have some actor value in it. Then use behaviour/attributes/set attribute (on the last created actor) to be the main actors self (found in scene/actors)

BATMOOSEMIKE

  • Posts: 8
IIRC you want the main actor to create the arm. Make the arm have some actor value in it. Then use behaviour/attributes/set attribute (on the last created actor) to be the main actors self (found in scene/actors)

Thanks for the help, however that sounds a bit confusing for me to follow without some screenshots. Could somebody please provide some?

xcmn

  • Posts: 89
Simple Answer:

If you put your code in the Scene's Events instead of the Actor's Events, you can choose any actor in your scene from the drop-box.

« Last Edit: June 02, 2015, 09:21:29 pm by xcmn »

xcmn

  • Posts: 89
Other Answer: Use Actor Attributes.

Do this within the Scene's events:

Create 2 Actor attributes called "Arm" and "Body". Then:
               
    -> When Created
               For Each Actor of Type "Arm"
                      Set "Arm" to Actor of Type
                For Each Actor of Type "Body"
                      Set "Body" to Actor of Type


Now you can choose "Arm" and "Body" in the drop menu (choose attribute), or drag them from the palette.

That's all. Read on for an alternate method.

Alternatively, you could create your Body and Arm actors when the scene begins and set your attributes to "last created actor":

In Scene Events:

->When Created
     Create "actor type - Body" at x, y
            set "Body" to "last created actor"
     Create "actor type - Arm" at x, y
            set "Arm" to "last created actor"





WATCH OUT with that Always event you're using. Be sure you have the necessary actors placed in the scene or created as the scene begins or your game will crash.

Or if they die. It causes the Always event to produce a null error. Cover your butt:

->Always
      If "Arm" is alive
            set x to "x of body" for arm
            set y to "y of body" for arm

BATMOOSEMIKE

  • Posts: 8
Thank you so much!

GeminisLOL

  • Posts: 18
how do I do the code (set Arm to actor of type) ??

TheIndieStation

  • *
  • Posts: 2259
Dont reactivate a post that is this old...
Instead create a new post and show us what you have tried.