I'm trying to get a projectile to move from character location, towards mouse location in a game.
Me and a friend are working on it together, and he looked up some stuff on vectors and this is what he came up with:
on beginSprite me
set mySprite to sprite(sprite(2))
set myVector to point (0, 0) -- USING POINT FORMAT
on prepareFrame me
if the mousedown then
set myVector to void
set myPrevLoc to point (sprite(1).locH, sprite(1).locV)
set the loc of mySprite to myPrevLoc
else if voidP (myVector) then
-- THROW BALL
set spriteLoc to point (the mouseH, the mouseV)
set the loc of mySprite to spriteLoc
set myVector to (spriteLoc - myPrevLoc)/20
-- MOVE BALL
set spriteLoch to the loch of myPrevLoc + myVector
set spriteLocv to the locv of myPrevLoc + myVector
set the loc of sprite mySprite to spriteLoc
it works to a degree. But there's a few problems. The projectile appears at character location for a second, and then spawn from mouse loc, though it travels in the correct location. Also, the further the mouse is from the character, the faster the projectile moves.
As a second request (if you have the time!) I want the projectile to stop moving if it collides with certain objects (like a wall or what have you). Any idea on how I could get this to work?