Discuss Scratch

TeeMee123
Scratcher
100+ posts

How do you make an accurate laser guidance system pointing towards cursor?

I have been working on a project called Melons vs Pumpkins which is where you have a spaceship with laser turrets that fire at falling pumpkins. It is all 2D, with a birds eye view. I have made a system where an invisible sprite shoots off from the turret until it reaches the edge, while using the pen tool to create a line behind it. When it reaches the edge it clears all pen and restarts (using a forever script). The invisible laser sprite (which creates the visible line behind it) points towards the cursor. However, only when the cursor is in a select few positions, will the laser actually touch the cursor.


Link to project: http://scratch.mit.edu/projects/17982288/

Please help me with this, as I am very puzzled!


I'm part of the collab Rankware Programming, see http://scratch.mit.edu/discuss/topic/42888 for details.
drmcw
Scratcher
1000+ posts

How do you make an accurate laser guidance system pointing towards cursor?

go to [laser turret v]
pen down
point towards [mouse-pointer v]
move (400) steps // Choose suitable number or could calculate distance to edge of screen
pen up

Ah just realised why yours has the problem and it's because you use a move 400 type block and since sprites cannot go offstage then it will get offset, so you do need to calculate the distance to the edge.

Last edited by drmcw (Feb. 19, 2014 14:56:19)


10 !
ScratchVaders or Galaga?
Maybe Eliza can help you decide?
TeeMee123
Scratcher
100+ posts

How do you make an accurate laser guidance system pointing towards cursor?

Ah, thanks!


I'm part of the collab Rankware Programming, see http://scratch.mit.edu/discuss/topic/42888 for details.
drmcw
Scratcher
1000+ posts

How do you make an accurate laser guidance system pointing towards cursor?

It's not as easy as it seems. See here That works for a laser pointing to the top of the screen. When it has to point to the sides then it will need to recalculate. Hopefully that will get you started.

10 !
ScratchVaders or Galaga?
Maybe Eliza can help you decide?

Powered by DjangoBB