how to use body:isTouching with multiple objects?

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
mzx
Prole
Posts: 1
Joined: Wed Aug 31, 2022 12:25 am

how to use body:isTouching with multiple objects?

Post by mzx »

hey y'all.
i'm messing around with the love.physics module or whatever, and im using the body:istouching function to determine whether or not the player controller can jump. however, this only works with one body at a time. is there any way to using the body:istouching function on a table or group of bodies so that i can easily add in new walls and stuff?

sorry if this is really shittily worded, im new to posting on this forum. :crazy:
User avatar
togFox
Party member
Posts: 835
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

Re: how to use body:isTouching with multiple objects?

Post by togFox »

It's not clear to me what you're asking.

You want to check istouching to check if a player can jump?

Or to add walls and stuff?

Anyway, this is on the wiki:

Code: Select all

touching = Body:isTouching( otherbody )
You have to cycle through all bodies, I guess, and see which one(s) are touching the player.
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/pad-and-pencil-gridiron
Ross
Party member
Posts: 100
Joined: Tue Mar 13, 2018 12:12 pm
Contact:

Re: how to use body:isTouching with multiple objects?

Post by Ross »

I don't think that's the right technique for the job. I would use the beginContact and endContact callbacks, and keep track of the touching bodies yourself. I think that makes more sense than trying to make a list of bodies yourself to check with isTouching().

Or you could use World:rayCast or World:queryBoundingBox.
Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests