I have an archer shootingan object at my mousecursor. The problem is, it sometimes misses. My hotspot is set to the center of each of my objects. Any idea what could be wrong?
So I figured it out. There are only 32 directions the arrow can travel using the Bouncing Ball movement type. (15 if you don't count straight up/straight down or backwards.) Is there any way to increase the number of directions using a different movement type? I can probably calculate actual degrees to get 360 directions (using y=mx+b), but if there is an easier way, I'd love to hear it =
• Always
→ Set Angle("Player") to ATan2(Y( "Player" )-YMouse, XMouse-X( "Player" ))
→ Set XPos("Bullet") to XPos("Bullet") + (Cos(Angle("Bullet")) * Velocity("Bullet")
→ Set YPos("Bullet") to YPos("Bullet") - (Sin(Angle("Bullet")) * Velocity("Bullet")
→ Set X("Bullet") to XPos("Bullet")
→ Set Y("Bullet") to YPos("Bullet")
• Repeat while left mouse button is pressed
→ Create Bullet at 0,0 from Player
→ Set Angle("Bullet") to Angle("Player")
→ Set XPos("Bullet") to X("Player")
→ Set YPos("Bullet") to Y("Player")
Instead of relying on trigonometric functions, just use dy and dx instead
The distance along the horizontal and vertical axis between the archer and the object can be calculated from their respective x and y coordinates, dx = x_object - x_archer and dy= y_object - y_archer.
Those number you get must then be 'normalized' to 1. Example: if the ratio dx/dy is" 50/10, normalize to 1/0.2 meaning 1 pixel to the right and 0.2 pixels up. You can multiply this ratio with the speed of your arrow and you've all the directions you need.
last night after posting I continued reading Calculus and read the word slope and I knew that was exactly the word I was looking for. I am a mathematichs teacher in Holland and sometimes I can't find the right English words for these cases, but the explanation mostly rings a bell.
You only need the slope because that will give you right direction, just remember to do the signs the right way.
Scaling the slope (triangle isn't it) should give you full control over the speed.