Hello guys,
I started learning lua and love2d this month. In my little game you can controll a character on the left hand side of the screen and move him up and down. Arrows spawn randomly on the right side and fly towards the player.
My problem is i dont know how to create independent colliders and keep track of the x and y coordinates. The script creates one collider and if a second one would spawn it crashes because i think it uses the same colider for the next arrow.
I tried almost 6 hours to get the result that i have now and dont know hot to solve this problem. Ive tried but not succeded.
I searched on forums, read the windfield github manuel, tried a lot, but nothing worked.
File is attached. Thank you!
Store and keep track of colliders x,y - windfield
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Store and keep track of colliders x,y - windfield
- Attachments
-
- main.lua
- (4.6 KiB) Downloaded 86 times
Re: Store and keep track of colliders x,y - windfield
I have read that you should store the colliders in a table and delete them after a set amount of time. I have tried that but could not work it out... I keep trying!
Re: Store and keep track of colliders x,y - windfield
Found a solution!
for _,a in pairs(arrow_flug) do
a.x = a.x - 5
if a.collider:enter('Player') then
player.leben = player.leben - 1
table.remove(arrow_flug, _)
a.collider:destroy()
elseif a.x < 10 then
table.remove(arrow_flug, _)
a.collider:destroy()
player.punkte = player.punkte + 1
end
end
No problems so far.
for _,a in pairs(arrow_flug) do
a.x = a.x - 5
if a.collider:enter('Player') then
player.leben = player.leben - 1
table.remove(arrow_flug, _)
a.collider:destroy()
elseif a.x < 10 then
table.remove(arrow_flug, _)
a.collider:destroy()
player.punkte = player.punkte + 1
end
end
No problems so far.
Re: Store and keep track of colliders x,y - windfield
Why you don't use the dt? So the speed is:Willi wrote: ↑Thu Jan 27, 2022 6:24 pm Found a solution!
No problems so far.Code: Select all
for _,a in pairs(arrow_flug) do a.x = a.x - 5 if a.collider:enter('Player') then player.leben = player.leben - 1 table.remove(arrow_flug, _) a.collider:destroy() elseif a.x < 10 then table.remove(arrow_flug, _) a.collider:destroy() player.punkte = player.punkte + 1 end end
vx = vx + ax*dt
And the position is:
x = x + vx*dt
Grüße
Who is online
Users browsing this forum: Ahrefs [Bot], whateverest and 5 guests