I have been reading quite a lot of articles about this subject, but I still have problems. I am sure this is because I suck at coding but I am here to learn.
My main dude has a 360 degree movement, now I want him to be able to shoot (or actually toss hammers). For this I use:
Press fire 2 -> Set posX of "Hammer" to Cos(rotY("player" ))*4
Set posY of "Hammer" to Sin(rotY("player" ))*4
posX and posY are values
rotY is the rotation value of the player
Always -> Set X of "Hammer" to X( "Hammer" )+posX( "Hammer" )
Set Y of "Hammer" to Y( "Hammer" )(posY( "Hammer" )
But this doesn't seem accurate, sometimes it's right, sometimes its a little off, which makes it hard to aim. What am I doing wrong?
"posX" and "posY" are actually "velocities", not "positions".
You need to store the positions in alterable values aswell, otherwise they will get rounded off (screen coordinates are always integers).
+ Press fire 2
-> Set velX of "Hammer" to Cos(rotY("player" ))*4
-> Set velY of "Hammer" to Sin(rotY("player" ))*4
+ Always
-> Set posX of "Hammer" to posX( "Hammer" )+ velX( "Hammer" )
-> Set posY of "Hammer" to posY( "Hammer" )- velY( "Hammer" )
-> Set X position of "Hammer" to posX("Hammer")
-> Set Y position of "Hammer" to posY("Hammer")