How do I respawn an object with Windfield?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
How do I respawn an object with Windfield?
I'm trying to develop a simple sports game where when a goal is scored, the ball goes back to it's original position after it bounces twice (it's a tennis like game). However when I tried implementing it in wind field, the ball and it's collision shape become detached and it doesn't work as intended.
-
- Party member
- Posts: 563
- Joined: Wed Oct 05, 2016 11:53 am
Re: How do I respawn an object with Windfield?
You'll need to either remove and reinsert the collider to the physics world, or update the collider's location to the spawn point without removing it. Decoupling probably happens if you're updating the visual representation, but not the physics representation, or vice versa.
Re: How do I respawn an object with Windfield?
I tried to see if I can destroy and create a new collider but I'm having the same issueMrFariator wrote: ↑Wed Jan 04, 2023 2:54 pm You'll need to either remove and reinsert the collider to the physics world, or update the collider's location to the spawn point without removing it. Decoupling probably happens if you're updating the visual representation, but not the physics representation, or vice versa.
(the code is under the ball.lua file)
- Attachments
-
- Game.love
- (200.61 KiB) Downloaded 46 times
-
- Party member
- Posts: 563
- Joined: Wed Oct 05, 2016 11:53 am
Re: How do I respawn an object with Windfield?
You seem to be amplifying your draw coordinates when rendering the ball, by a factor of two. As a proof of concept of that, this fixed the issue:
As such, this doesn't seem to be an issue with windfield, but rather with how you're rendering the visuals. Somewhere in your code the visual and physics coordinates stop matching, creating this sort of decoupling issue when you try to reset the ball. Would need to look further into your main.lua to better understand the issue.
Code: Select all
function Ball:winOrLose()
if bounceCounter == 2 and self.x < 320 then
playerTwoScore = playerTwoScore + 1
self.ball:destroy()
self.x = 600
self.y = 100
self.ball = World:newCircleCollider(self.x, self.y, self.rad)
self.x = 600/2 -- render the ball at half of the physics' representation coordinates
self.y = 100/2
-- ...rest of code
Re: How do I respawn an object with Windfield?
The ball did get set back to the original position but it's not falling. I tried setting the type to dynamic but it still stayed in placeMrFariator wrote: ↑Wed Jan 04, 2023 4:13 pm You seem to be amplifying your draw coordinates when rendering the ball, by a factor of two. As a proof of concept of that, this fixed the issue:As such, this doesn't seem to be an issue with windfield, but rather with how you're rendering the visuals. Somewhere in your code the visual and physics coordinates stop matching, creating this sort of decoupling issue when you try to reset the ball. Would need to look further into your main.lua to better understand the issue.Code: Select all
function Ball:winOrLose() if bounceCounter == 2 and self.x < 320 then playerTwoScore = playerTwoScore + 1 self.ball:destroy() self.x = 600 self.y = 100 self.ball = World:newCircleCollider(self.x, self.y, self.rad) self.x = 600/2 -- render the ball at half of the physics' representation coordinates self.y = 100/2 -- ...rest of code
-
- Party member
- Posts: 563
- Joined: Wed Oct 05, 2016 11:53 am
Re: How do I respawn an object with Windfield?
Oh, right. That's because you never set the bounceCounter back to 0, so the ball is repeatedly getting reset back to its starting position due to the code in the winOrLose function.
Re: How do I respawn an object with Windfield?
Oh I didn't think of that. Sorry for overlooking something so simple. Thanks for the correction!
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot], Semrush [Bot] and 6 guests