How do you create a beam or ray?
deomacius
Member Posts: 10
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.
deomacius.
Comments
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
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.
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.
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.
deomacius.
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.
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
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