I've been trying to start a small project with the Player object able to change shape and size, similarly to how was done for the ball in this thread: viewtopic.php?f=4&t=28746&p=94878&hilit ... ody#p94878
This has been accomplished for the ball by increasing the circle radius, however after a bit of research I can't find how this effect would be achieved for a rectangle or polygon shape.
On duplicate objects, I have an array to create an object several times and can collide a square physics object with every instance of the object, however when 'checking' for collision with the square object for a jump effect it is only found true on the last object in the table, likely as all others have been overwritten and that last object is the only one with the official title "object.square.body" /shape /fixture.
Below is a reduced example of the type of code I am working with.
Changing love.physics object sizes and creating duplicate objects
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 17
- Joined: Mon Jul 30, 2012 9:15 pm
Changing love.physics object sizes and creating duplicate objects
- Attachments
-
- Redacted.love
- (3.01 KiB) Downloaded 175 times
Re: Changing love.physics object sizes and creating duplicate objects
I haven't found any way to resize rectangles either, but when it comes to generating a new object on resize, why do you want to store all the old objects? In any case they should still exist as long as there is a reference to them somewhere.
I'd reccomend generating a new shape, updating the fixture to connect the body to the new shape rather than the old, destroy the old shape and let it get garbage collected. This could still be pretty slow if you resize the rectangle often, or have to resize a lot of rectangles, but I think it's probably the best that can be done for now if you need it to be an actual physics object.
If you don't necessarily need that, there are more efficient options. If you don't need your rectangle to bounce off things or rotate - only detect collisions, you can use world:queryBoundingBox in love.update instead of initializing a full object for it, and manage its size with ordinary table elements.
If you also want to be able to rotate it, or apply this to any polygonal shape, breezefield (https://github.com/HDictus/breezefield) and windfield(https://github.com/adnzzzzZ/windfield) each have a world:queryPolygonArea() method. (for windfield you might want to see this PR if you're working with circles https://github.com/adnzzzzZ/windfield/pull/13/files)
I'd reccomend generating a new shape, updating the fixture to connect the body to the new shape rather than the old, destroy the old shape and let it get garbage collected. This could still be pretty slow if you resize the rectangle often, or have to resize a lot of rectangles, but I think it's probably the best that can be done for now if you need it to be an actual physics object.
If you don't necessarily need that, there are more efficient options. If you don't need your rectangle to bounce off things or rotate - only detect collisions, you can use world:queryBoundingBox in love.update instead of initializing a full object for it, and manage its size with ordinary table elements.
If you also want to be able to rotate it, or apply this to any polygonal shape, breezefield (https://github.com/HDictus/breezefield) and windfield(https://github.com/adnzzzzZ/windfield) each have a world:queryPolygonArea() method. (for windfield you might want to see this PR if you're working with circles https://github.com/adnzzzzZ/windfield/pull/13/files)
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 4 guests