Attaching an entity's collision box to another moving object

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
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
Joined: Thu Dec 10, 2020 1:57 am

Attaching an entity's collision box to another moving object

Post by Gunroar:Cannon() »

I have an entity that attaches its collision box to another object so that it moves next to it like it's being carried. But then in my collision system I force-move the attached entity and make it not solid so that it can go through walls while being carried (it still looks natural in a way, this is fine) and then when it's thrown (yes, thrown) I set it back to solid after a while (so it doesn't glitch with the thrower or walls it was inside).
This is also fine except that sometimes the throw may be naturally off and the entity may end up sliding through walls.

So rather than my hacky way of carrying is there a way to ...would I say, add the entity's width/height to the grabber so that it can't glitch through walls OR is there a better way I could be handling all this? (I kind of also wanted a possibility where an object could be detached if it can't pass through a place with the carrier)

To see what I mean you can check this .love file. No need to do anything, just when the thingy with a hand "grabs" the soul it will then throw it at the box and then there's a chance the freaky glitchy stuff would happen. If not it can be restarted or it will try to get you and throw you again. (Yes, you are the entity being thrown here).
Attachments
eg.love
Eg as in example, not as in egg...
(1.09 MiB) Downloaded 30 times
Last edited by Gunroar:Cannon() on Mon Jul 04, 2022 8:14 am, edited 1 time in total.
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
darkfrei
Party member
Posts: 1169
Joined: Sat Feb 08, 2020 11:09 pm

Re: Attaching an entity's collision box to another moving object

Post by darkfrei »

In the "Fïsh Fïllët" in the module blocks.lua I've made the solution to same situation.
1. The player has some dx and dy for his movement.
2. The given dx, dy will be provided to the carried object.
3. If the carried object has collision, then return the reduced dx and dy from distance that maximum what that carried object can move.
4. Move the player and his object by this reduced dx and dy. The reduced dx and dy can be 0, 0 too, so no movement at all.
Last edited by darkfrei on Mon Jul 04, 2022 10:33 am, edited 3 times in total.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
Joined: Thu Dec 10, 2020 1:57 am

Re: Attaching an entity's collision box to another moving object

Post by Gunroar:Cannon() »

darkfrei wrote: Mon Jul 04, 2022 7:17 am In the "Fish Fillët" in the module blocks.lua I've made the solution to same situation.
1. The player has some dx and dt for his movement..
I'm guessing you meant to type "dy".

And what does dx/dy mean in the code. Velocity, displacement between the two options or...
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
darkfrei
Party member
Posts: 1169
Joined: Sat Feb 08, 2020 11:09 pm

Re: Attaching an entity's collision box to another moving object

Post by darkfrei »

Gunroar:Cannon() wrote: Mon Jul 04, 2022 8:10 am
darkfrei wrote: Mon Jul 04, 2022 7:17 am In the "Fish Fillët" in the module blocks.lua I've made the solution to same situation.
1. The player has some dx and dt for his movement..
I'm guessing you meant to type "dy".

And what does dx/dy mean in the code. Velocity, displacement between the two options or...
Yes, dx and dy, thanks. It is the your dx=vx*dt; dy=vy*dt. It's the vector of the player's displacement in the actual tick.
So if the player goes 10 pixels in this step, but the carried object can be moved just 5 pixels until the collision, then the player goes to the 5 pixels too.

In this way the collision of the carried object is a collision for the player too.


Normally the collision detection is:
Player: can I move myself to n pixels?
Collision detection: No, but you can move yourself to m (less than n) pixels.
Player: ok, then I move myself to m pixels.

Collision by the player, that holds other object:
Player: can I move myself to n pixels?
Collision detection: yes.
Player: can I also move the object to n pixels?
Collision detection: no, but you can move it to m pixels.
Player: ok, then I move myself to m pixels and my carried object will be moved to m pixels too.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
Joined: Thu Dec 10, 2020 1:57 am

Re: Attaching an entity's collision box to another moving object

Post by Gunroar:Cannon() »

darkfrei wrote: Mon Jul 04, 2022 8:35 am So if the player goes 10 pixels in this step, but the carried object can be moved just 5 pixels until the collision, then the player goes to the 5 pixels too.

In this way the collision of the carried object is a collision for the player too.


Normally the collision detection is:
Player: can I move myself to n pixels?
Collision detection: No, but you can move yourself to m (less than n) pixels.
Player: ok, then I move myself to m pixels.

Collision by the player, that holds other object:
Player: can I move myself to n pixels?
Collision detection: yes.
Player: can I also move the object to n pixels?
Collision detection: no, but you can move it to m pixels.
Player: ok, then I move myself to m pixels and my carried object will be moved to m pixels too.
*facepalm*
Of course!! Ha, thanks. And I just did a working one by making the carrier and carried object one bigger rectangle that counts for both their collisions but your way is more elegant. I'll try it :ultrahappy:
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
Post Reply

Who is online

Users browsing this forum: No registered users and 48 guests