How do you create a beam or ray?

deomaciusdeomacius Member Posts: 10
edited November -1 in Working with GS (Mac)
Is there a tutorial or something that explains how one would create either a destructive beam or a beam with a "tractor beam" effect?

deomacius.

Comments

  • quantumsheepquantumsheep Member Posts: 8,188
    Actually, this is a very good question...

    I attempted it but gave up as I wasn't getting the results I wanted. I had a beam that took up most of the screen, and it just looked silly.

    I assume you'd constrain it to the x and y coords of your ship.

    As for a tractor beam, you could make an object move towards the beam if the beam is activated.

    In both these cases I would set up two variables - Player ship X and player ship Y and then constrain these to the X and Y position of your ship.

    I didn't persevere with it I'm afraid so this is all theoretical - I'm sure CodeMonkey will have all the answers as usual!

    (as a side note, I came up with an even better idea for the lasers - you'll see what it is in an upcoming iPhone game) :)

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • TobyToby Member Posts: 478
    I would create a cone shaped graphic in a graphics or vector program like Photoshop animate it if you can and put a little falloff at the edges. Then import and assign to an actor and add a little alpha if not applied on the image. As QS indicated, constrain the XY of the beam to your player actor with an offset so the beam source eminates from the bottom of the ship. Assign some simple collision rules to your 'to be beamed' objects saying on beam collision accelerate toward player XY at a slow rate and maybe adjust the scale as the beamed object gets closer to the player. I guess your game involves abducting cows or humans huh? Might need some gravity so if the beam drops off the target they fall back down again.

    It would be cool to make the beam appear on keypress and set a game attribute (Boolean) to true which tells the beamed actors to start moving when collided with. Not too difficult to build.
  • deomaciusdeomacius Member Posts: 10
    Thank you for responding so quickly, quantumsheep. I'm new to GameSalad so any advice is good advice.

    Toby, you are wise beyond your years! I MAY be trying to abduct cows... or other living organisms ;-) I already created the beam graphic (a placeholder really, while I try to get the mechanics down). I'll do as you both suggested.

    Again, thanks for both responding so quickly.
  • CobraCobra Member Posts: 160
    I have something similar in my upcoming game. It was a serious PITA, but totally worth it. :D

    I'm guessing the problem you are having is with the position of the beam, e.g. a tractor beam that draws a line between two potentially moving objects. I would suggest figuring out where the beam's start and end points are -- for example, if the player fires the beam and hits an enemy ship, your beam actor needs to know the X&Y position of the player, and the X&Y position of the enemy ship. You can use game attributes to pass this information.

    Then your beam actor gets to do some geometry:
    - Constrain self.Position to the midpoint of those two points.
    - Constrain self.Rotation to the angle between those two points.
    - Constrain self.Size.Width to the distance between those two points.

    EDIT: Toby's suggestion is of course much better if you would like your player to aim. :D
  • deomaciusdeomacius Member Posts: 10
    Thanks Cobra. Is there a more detailed explanation for how to set up variables or how to use the constrain behavior based on another actor's X and Y position? I've scanned over the wiki and it's not obvious to my untrained eyes.

    deomacius.
  • CobraCobra Member Posts: 160
    An actor can't directly access another actor's attributes, but you can pass information from one to the other using game attributes.

    For example, say you want to draw a beam between two actors DeathStar and Alderaan. You could create two game attributes, game.AlderaanX and game.AlderaanY, and have the Alderaan actor do this:

    Constrain attribute game.AlderaanX to self.Position.X
    Constrain attribute game.AlderaanY to self.Position.Y

    Now DeathStar can access Alderaan's position through game.AlderaanX and game.AlderaanY, and of course it can access its own position, so there you go. :)
  • quantumsheepquantumsheep Member Posts: 8,188
    Right, here goes!

    Create two variables as integers - call the playerX and playerY

    On your ship actor:

    Use two constrain Attribute behaviours:

    One should say - Constrain Attribute game.playerX to self.position x
    The other says - constrain Attribute game.playerY to self.position x

    the game.player whatever bit is your variable.
    The self.position bit is that actor's self position.

    Use the 'e' button to edit these empty boxes and choose the relevant bits from the list.

    Now, you'll want your beam to spawn at your player's position. So you put in a rule

    When button whatever is pressed

    drag in a Spawn attribute to this rule.

    Actor - put in the beam.

    Position > game.playerX Position ^ game.playerY

    This will spawn the beam actor at your player's current position, from its centre. You may want to add a bit to have it spawn at the nose of your ship, for example, by changing the position> value to game.playerX+15 or something.

    If you want the beam to travel up and down, left and right with your actor while it's on, I'm not sure exactly how to do that. Like I said, I gave up on it.

    Hope that helps though!

    Cheers,

    QS

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • deomaciusdeomacius Member Posts: 10
    Cobra and quantumshep, thanks again for your generous tips. I can't wait to play with this tonight.
  • quantumsheepquantumsheep Member Posts: 8,188
    There is nothing better, game wise, than having an idea in your head, working out how to do it, and then seeing it work.

    You feel like a genius! :)

    Sometimes though, a little help goes a long way!

    Good luck with it deomacius - your game already sounds like one I'd like to play! :)

    QS

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

Sign In or Register to comment.