Discuss Scratch

Grigos
Scratcher
45 posts

How to make a flexible laser?

To be more specific, its a laser that instantly connects from the enemy to the player.

Something like this:
https://youtu.be/i6GKsHigAQM?t=26

The problem is how do I make it longer or shorter depending on where the player is?
Grigos
Scratcher
45 posts

How to make a flexible laser?

More detail:

- Enemy spawns, creates a line/sprite instantly connecting from the enemy to the player's character x,y
- It does not follow the player's character
- Ghost effect slowly reaching 100 or animated sprite
ResExsention
New Scratcher
1000+ posts

How to make a flexible laser?

Okay.

First, create a laser sprite.

Next, in the enemy code, you need to create a clone of the laser and position that clone so that one end is touching the enemy and the other end is going off the screen. Keep it like that for about 0.5 seconds then delete that clone

Then, in the player code just set it in a way so that if the player is touching the laser clone, kill it.

Can't be that hard…

Anyway, should the video be there? This is a kids website, after all. Idk, I'll let someone else handle it.

Last edited by ResExsention (May 10, 2019 16:33:02)


Infrequently active.

It feels weird to see how far we've come. I hope you're well, wherever you are!
Grigos
Scratcher
45 posts

How to make a flexible laser?

ResExsention wrote:

Okay.

First, create a laser sprite.

Next, in the enemy code, you need to create a clone of the laser and position that clone so that one end is touching the enemy and the other end is going off the screen. Keep it like that for about 0.5 seconds then delete that clone

Then, in the player code just set it in a way so that if the player is touching the laser clone, kill it.

Can't be that hard…

Anyway, should the video be there? This is a kids website, after all. Idk, I'll let someone else handle it.

But why would the other end go off screen?
I want the enemy to laser the player, so, the laser will be starting from the enemy's weapon and ending on the player, but without the laser moving, it just appears and disappears.

Problem is how do I control how long it is

Now I understand what you meant, but this way I'd have to animate it getting longer until it reaches the player's x,y

Last edited by Grigos (May 10, 2019 19:41:13)

ResExsention
New Scratcher
1000+ posts

How to make a flexible laser?

You don't have to animate it, actually.

The reason why I suggested letting it go offscreen was to make it look like the player got cut in half (hit) or it just missed (missed).

I think the way the laser acts if it's a miss is fine, but if you want it to stop at the player, you should instead scrap my previous idea and create a small laser bolt. Then, use scripts to move it in a way that makes it move so fast that it looks like the laser was just one long beam. If it hits the player use:

hide

To make the beam disappear. And again, use clones.

Infrequently active.

It feels weird to see how far we've come. I hope you're well, wherever you are!
StrangeMagic32
Scratcher
1000+ posts

How to make a flexible laser?

Do you want a laser like these?
https://scratch.mit.edu/projects/183157839/
https://scratch.mit.edu/projects/170343781/


“Remember the worth of souls is great in the sight of God;”
- Doctrine and Covenants 18:10


I have since moved to @JollyWinter
Grigos
Scratcher
45 posts

How to make a flexible laser?

I'd probably get it to work if I took StrangeMagic32's laser and made it stop at the players first X,Y
But I never used the pen and won't bother learning it just for this

I'll just make a laser sprite go from the enemy to offscreen in the direction of the player.

Last edited by Grigos (May 11, 2019 13:35:14)

Grigos
Scratcher
45 posts

How to make a flexible laser?

Note, my first idea was that the laser would not miss.
It would just connect from the enemy to the player's X.Y at the time, stop there and slowly disappear.
Tallented-Code-bot
Scratcher
100+ posts

How to make a flexible laser?

if the player and enemy were separate sprites, what you should do is this.
Make a costume in the enemy for the laser. When the laser is triggered, create a clone of the enemy.l
When the enemy is cloned, the clone changes its costume to laser, points toward the player, and
keeps moving forward until it either hits the player or hits the edge. If the player does not move while the laser isl going forward,
it should always hit the player.
Hope that helped
Grigos
Scratcher
45 posts

How to make a flexible laser?

Tallented-Code-bot wrote:

if the player and enemy were separate sprites, what you should do is this.
Make a costume in the enemy for the laser. When the laser is triggered, create a clone of the enemy.l
When the enemy is cloned, the clone changes its costume to laser, points toward the player, and
keeps moving forward until it either hits the player or hits the edge. If the player does not move while the laser isl going forward,
it should always hit the player.
Hope that helped

That's not the point.
Shooting a laser that moves until it hits the player is easy.

What I want:
1) Enemy spawns
2) A line connecting the enemy and the player's X,Y appears.
3) The line slowly disappears.

It's not supposed to miss. It's not supposed to keep going until it hits the edge.

Last edited by Grigos (May 11, 2019 14:04:00)

ResExsention
New Scratcher
1000+ posts

How to make a flexible laser?

Grigos wrote:

Tallented-Code-bot wrote:

if the player and enemy were separate sprites, what you should do is this.
Make a costume in the enemy for the laser. When the laser is triggered, create a clone of the enemy.l
When the enemy is cloned, the clone changes its costume to laser, points toward the player, and
keeps moving forward until it either hits the player or hits the edge. If the player does not move while the laser isl going forward,
it should always hit the player.
Hope that helped

That's not the point.
Shooting a laser that moves until it hits the player is easy.

What I want:
1) Enemy spawns
2) A line connecting the enemy and the player's X,Y appears.
3) The line slowly disappears.

It's not supposed to miss. It's not supposed to keep going until it hits the edge.

You're saying it should go up to the edge, but if it hits something (like the player) it deals damage and then fades without ever actually hitting the edge?

Infrequently active.

It feels weird to see how far we've come. I hope you're well, wherever you are!
Grigos
Scratcher
45 posts

How to make a flexible laser?

ResExsention wrote:

Grigos wrote:

Tallented-Code-bot wrote:

if the player and enemy were separate sprites, what you should do is this.
Make a costume in the enemy for the laser. When the laser is triggered, create a clone of the enemy.l
When the enemy is cloned, the clone changes its costume to laser, points toward the player, and
keeps moving forward until it either hits the player or hits the edge. If the player does not move while the laser isl going forward,
it should always hit the player.
Hope that helped

That's not the point.
Shooting a laser that moves until it hits the player is easy.

What I want:
1) Enemy spawns
2) A line connecting the enemy and the player's X,Y appears.
3) The line slowly disappears.

It's not supposed to miss. It's not supposed to keep going until it hits the edge.

You're saying it should go up to the edge, but if it hits something (like the player) it deals damage and then fades without ever actually hitting the edge?

Forget the edge. The laser is never supposed to interact with it
Even if it misses the players character/sprite, it stops at their first X,Y (The players X,Y when the laser appeared)

Also why am I not receiving notifications even with this thread followed

Last edited by Grigos (May 11, 2019 14:22:42)

Grigos
Scratcher
45 posts

How to make a flexible laser?

Also also there is nothing to discuss anymore, the way I want it to work would have to include the pen feature and I'm not planning on learning that.

So I'll just make a bigass laser go offscreen and be done with it

Last edited by Grigos (May 11, 2019 14:25:47)

StrangeMagic32
Scratcher
1000+ posts

How to make a flexible laser?

Does this work for you?
https://scratch.mit.edu/projects/308817925/


“Remember the worth of souls is great in the sight of God;”
- Doctrine and Covenants 18:10


I have since moved to @JollyWinter
LittleBitMore
Scratcher
100+ posts

How to make a flexible laser?

You could use this code:
when I receive [shoot player with laser v]
set pen color to [#ff0000] //whatever color you want
repeat (10) //makes it wait a little bit while ALSO keeping the laser targeted at the player
clear
go to [enemy v]
pen down
go to [player v]
pen up
end
repeat (10) //same thing, but makes it dimmer while doing so
clear
change pen shade by (10) //might need to adjust if your backdrop isn't white
go to [enemy v]
pen down
go to [player v]
pen up
end
The effect results in the laser always hitting the player, always pointing at the player, and always manage to contact the player every single time it fires, and will remain tracking the player for a little bit until it fades out. There is no chance of not hitting the player. If you want it to slowly progress towards the player, or interact with walls, share the project and I'll remix it with the laser code (both of those are just too big and complex to fit well into these discuss posts)
You could make the player ALSO receive the broadcast and do something accordingly (such as take damage or die).
Hope it works for you!

Last edited by LittleBitMore (May 11, 2019 14:50:36)


~ ~ ~ ~ Testing signature styles infinitely and eternally. ~ ~ ~ ~
Grigos
Scratcher
45 posts

How to make a flexible laser?

StrangeMagic32 wrote:

Does this work for you?
https://scratch.mit.edu/projects/308817925/

Whoops! Our server is Scratch'ing its head

LittleBitMore wrote:

You could use this code:
when I receive [shoot player with laser v]
set pen color to [#ff0000] //whatever color you want
repeat (10) //makes it wait a little bit while ALSO keeping the laser targeted at the player
clear
go to [enemy v]
pen down
go to [player v]
pen up
end
repeat (10) //same thing, but makes it dimmer while doing so
clear
change pen shade by (10) //might need to adjust if your backdrop isn't white
go to [enemy v]
pen down
go to [player v]
pen up
end
The effect results in the laser always hitting the player, always pointing at the player, and always manage to contact the player every single time it fires, and will remain tracking the player for a little bit until it fades out. There is no chance of not hitting the player. If you want it to slowly progress towards the player, or interact with walls, share the project and I'll remix it with the laser code (both of those are just too big and complex to fit well into these discuss posts)
You could make the player ALSO receive the broadcast and do something accordingly (such as take damage or die).
Hope it works for you!

I'll try it and update you.
Grigos
Scratcher
45 posts

How to make a flexible laser?

@LittleBitMore

Yeah that's it.
I was going to change the go to player to go to player's first X,Y, since the laser wasnt supposed to follow them.
But I like it and I'll leave it as is and credit you.

My question is, would it be possible to do something like this but with a sprite instead? It'd look better animated

Last edited by Grigos (May 11, 2019 15:55:12)

ResExsention
New Scratcher
1000+ posts

How to make a flexible laser?

Grigos wrote:

@LittleBitMore

Yeah that's it.
I was going to change the go to player to go to player's first X,Y, since the laser wasnt supposed to follow them.
But I like it and I'll leave it as is and credit you.

My question is, would it be possible to do something like this but with a sprite instead? It'd look better animated

If you're looking for glowy lasers, then you're kind of out of luck in Scratch. Only more powerful engines can have surface light components, or maybe it'd just be too complicated for the young people.

Well, you could use a sprite, however the biggest problem there is making the laser not continue past the player.

Well, my suggestion is this. If you are unable to make one super fast laser that looks like it's just one beam, try instead creating a lot of clones that don't have ends (so that they fit together nicely) and then just release an entire volley of them in a line, deleting those clones as they leave the game area or hit an object.

Wow, making workarounds for an engine that doesn't support particle effects is difficult…

Infrequently active.

It feels weird to see how far we've come. I hope you're well, wherever you are!
Grigos
Scratcher
45 posts

How to make a flexible laser?

ResExsention wrote:

Grigos wrote:

@LittleBitMore

Yeah that's it.
I was going to change the go to player to go to player's first X,Y, since the laser wasnt supposed to follow them.
But I like it and I'll leave it as is and credit you.

My question is, would it be possible to do something like this but with a sprite instead? It'd look better animated

If you're looking for glowy lasers, then you're kind of out of luck in Scratch. Only more powerful engines can have surface light components, or maybe it'd just be too complicated for the young people.

Well, you could use a sprite, however the biggest problem there is making the laser not continue past the player.

Well, my suggestion is this. If you are unable to make one super fast laser that looks like it's just one beam, try instead creating a lot of clones that don't have ends (so that they fit together nicely) and then just release an entire volley of them in a line, deleting those clones as they leave the game area or hit an object.

Wow, making workarounds for an engine that doesn't support particle effects is difficult…


Yes multiple animated clones to make a perfect laser would be an option
StrangeMagic32
Scratcher
1000+ posts

How to make a flexible laser?

Grigos wrote:

StrangeMagic32 wrote:

Does this work for you?
https://scratch.mit.edu/projects/308817925/

Whoops! Our server is Scratch'ing its head
sorry my bad, shared


“Remember the worth of souls is great in the sight of God;”
- Doctrine and Covenants 18:10


I have since moved to @JollyWinter

Powered by DjangoBB