Need help with bullet velocity
Monkey Forums/Monkey Programming/Need help with bullet velocity
| ||
Hey guys, Making a shooter game and I'm hoping you can help me with my small problem. Below is the current code I have written, which is close but no cigar. This is supposed to be bullets shot from the enemy toward the player. If sx > ex speedX = sx / ex horizontalMove = (-speedX * speed) - speed Else speedX = ex / sx horizontalMove = (speedX * speed) + speed End If sy > ey speedY = sy / ey verticalMove = (-speedY * speed) - speed Else speedY = ey / sy verticalMove = (speedY * speed) + speed End Assume sx (start X), sy (start Y), ex (player's X position/end X), ey (player's Y position/end Y) and speed is the bullet's standard speed. horizontalMove and verticalMove then become the bullet object's actual x/y speed to travel towards the player's position. I need the bullets to go exactly where the player currently is. Help meeeeee!! :) |
| ||
Here, I mocked-up this example up quickly. Also, you may wanna brush up on your math if you can't solve this. |
| ||
Thanks for that Goodlookinguy! (that sounds like a come-on) :) I'll give it a try later when back at home. |
| ||
got this working, thanks mate. I had to reverse the bullet x and y addition though as it was going the opposite direction: ... i.sx -= Cos(i.angle) * i.speed * dt.delta i.sy -= Sin(i.angle) * i.speed * dt.delta ... Still, works a treat thanks! |
| ||
I had it pointing from player to enemy. To get the exact opposite effect you just have to change theses lines.bullet.x = 10 bullet.y = 10 Local angle:Float = ATan2(enemy.y - player.y, enemy.x - player.x) to bullet.x = enemy.x bullet.y = enemy.y Local angle:Float = ATan2(player.y - enemy.y, player.x - enemy.x) |
| ||
Ah I see now, thanks! |