How can I play with Knives?

svnsvn Member Posts: 445
edited November -1 in Working with GS (Mac)
I have an enemy actor, and I want him to throw a knife, left if he is facing left and right if he is facing right. The problem is not spawning the knife, but telling it which way to go. The only thing I can think of is creating a game.attribute for each instance of this enemy actor, and create several instances of the knife, each corresponding to a separate instance of the actor. Is there any less time-and-memory-consuming way?

EDIT: Also, I wish to bring the same mechanic into play involving an enemy with a club. Would the same mechanics apply, and if not, what mechanics to apply?

Comments

  • COBGamesCOBGames Member Posts: 114
    i'd say create a new boolean attribute and if it is set to true then have it do one thing and if false then do the other. you could name the attribute like something is_left or is_right, whichever you want.
  • svnsvn Member Posts: 445
    Well, actually, that's kind of what I want to avoid. I don't want some game attribute telling all 23 enemies to throw their spears at some random crate or mushroom ahead or behind them.
  • COBGamesCOBGames Member Posts: 114
    i'd say a local attribute for that enemy then?
  • svnsvn Member Posts: 445
    Yeah, but that would be pretty time-consuming. Anyone else have any ideas?
  • SinequanonSinequanon Member Posts: 35
    Use the direction property on the spawn. I made a quick prototype with a white block "throwing" red blocks and said when linear.velocity.x > 0, spawn actor "knife" direction 0, otherwise spawn actor "knife" direction 180 (using the direction wheel).

    This could be done with a boolean property set on each spawner determining whether it's left or right, or with the graphics flip properties or however you determine direction.

    For the knife, I would set them at Alpha 0 and have a timer that after .1 seconds, set their alpha to 1. Prior to that timer, have it determine what direction it's going by its linear velocity X. If you need to set any properties such as rotation or flip graphics. If your game doesn't move very fast, you can probably get away with not using the timer.
Sign In or Register to comment.