So this is the problem:
I am a white square following the mouse.
The machinegun the AI is firing however is not pointing in the correct direction.
It's origin is not even near the green AI
...
What I would wish:
The machine gun actually aims towards the player.
What might be wrong:
Check my MissileFire function first, I think there is something wrong with the mathematics there.
Glitches with the automatic machine gun
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 15
- Joined: Sat Aug 19, 2017 9:13 am
Glitches with the automatic machine gun
- Attachments
-
- main.lua
- (1.85 KiB) Downloaded 95 times
Re: Glitches with the automatic machine gun
So let's just get this one in:
The green square in the middle is an AI (enemy?)
And that other green thing is the machine gun.
Now, how should your game work again?
The white square is you.The green square in the middle is an AI (enemy?)
And that other green thing is the machine gun.
Now, how should your game work again?
Re: Glitches with the automatic machine gun
Okay, I think I got a good handle of what's going on. Let's start with your starting coordinates:
On this part, it seems that you want the Missiles start coming out from the CENTER of the enemy. But you first have to define the enemy's width and height before you can do that. And, also you're referencing the player rather than the enemy.
So to simplify things, I did this:
It's a step, but we got the enemy shooting missiles. Now we have to solve for the correct direction.
Code: Select all
function EnemyMissile(x1,x2,y1,y2)
local StartX = x1/2
local StartY = y1/2
...
So to simplify things, I did this:
Code: Select all
function EnemyMissile(x1,x2,y1,y2)
local StartX = x2
local StartY = y2
...
Re: Glitches with the automatic machine gun
I got it. This is your original code
Just switch the x's an y's in the math.atan2():
Code: Select all
function EnemyMissile(x1,x2,y1,y2)
...
local angle = math.atan2((x1 - x2), (y1 - y2))
Code: Select all
function EnemyMissile(x1,x2,y1,y2)
...
local angle = math.atan2((y1 - y2), (x1 - x2))
-
- Prole
- Posts: 15
- Joined: Sat Aug 19, 2017 9:13 am
Re: Glitches with the automatic machine gun
Thanks sphyrth!
Who is online
Users browsing this forum: Bing [Bot] and 8 guests