Document stub.png This article is a stub. It may be incomplete, unfinished, or have missing parts/sections. If the article can be expanded, please do so! There may be suggestions on its talk page. (October 2019)
DocumentInQuestion.png It has been suggested that this page's contents be merged with the page Projectile Simulation. You can discuss this on the page's talk page. (May 2021)

Projectiles are used in a wide variety of games, such as shooters, and are not very complicated to make. This details have to make a projectile engine on Scratch.

Script

Here is the script for the projectile engine:

when gf clicked
forever
hide
set rotation style [all around v] // rotation mode
go to (player1 v) // go to sprite currently shooting
point towards (mouse pointer v) // to aim your projectile
if <mouse down?> then
if <<(direction) < (120)> and <(direction) > (-120)>> then // to stop unwanted glitches
if <(direction) < (0)> then
show
repeat until <<touching (edge v)?> or<touching (player2 v)?>> // repeat until collision
if <(direction) < (178)> then // if not pointing straight down
move [10] steps // move forward
turn left [2] degrees // constantly dip downwards
else
move [10] steps // move straight down
end
end
move [10] steps // continue colliding with object after initial collision
hide
else
show
repeat until <<touching (edge v)?> or<touching (player2 v)?>> // repeat until collision
if <(direction) > (-178)> then // if not pointing straight down
move [10] steps // move forward
turn right [2] degrees // constantly dip downwards
else
move [10] steps // move straight down
end
end
move [10] steps // continue colliding with object after initial collision
hide
end
end
end
end

The most important part to this is that the projectile is in the center of its costume, pointing right, otherwise, the projectile will not travel smoothly in the air.

See Also