How do I respawn an object with Windfield?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
MaxGamz
Party member
Posts: 107
Joined: Fri Oct 28, 2022 3:09 am

How do I respawn an object with Windfield?

Post by MaxGamz »

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.
MrFariator
Party member
Posts: 563
Joined: Wed Oct 05, 2016 11:53 am

Re: How do I respawn an object with Windfield?

Post by MrFariator »

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.
MaxGamz
Party member
Posts: 107
Joined: Fri Oct 28, 2022 3:09 am

Re: How do I respawn an object with Windfield?

Post by MaxGamz »

MrFariator 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.
I tried to see if I can destroy and create a new collider but I'm having the same issue

(the code is under the ball.lua file)
Attachments
Game.love
(200.61 KiB) Downloaded 46 times
MrFariator
Party member
Posts: 563
Joined: Wed Oct 05, 2016 11:53 am

Re: How do I respawn an object with Windfield?

Post by MrFariator »

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:

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
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.
MaxGamz
Party member
Posts: 107
Joined: Fri Oct 28, 2022 3:09 am

Re: How do I respawn an object with Windfield?

Post by MaxGamz »

MrFariator 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:

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
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.
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 place
MrFariator
Party member
Posts: 563
Joined: Wed Oct 05, 2016 11:53 am

Re: How do I respawn an object with Windfield?

Post by MrFariator »

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.
MaxGamz
Party member
Posts: 107
Joined: Fri Oct 28, 2022 3:09 am

Re: How do I respawn an object with Windfield?

Post by MaxGamz »

Oh I didn't think of that. Sorry for overlooking something so simple. Thanks for the correction!
Post Reply

Who is online

Users browsing this forum: Amazon [Bot], Bing [Bot], GetAsync and 5 guests