Hello, all.
This is my first post here, and it's mostly due to the fact that I haven't needed to post a question before.
I am working on a game that I have mostly figured out in theory; however, I have run into a problem in implementing these portals. Basically, I want them to work like the ones from Portal: The Flash Version, but I can't figure out a good way of triggering the portals so that when an object is moved into Portal A, it comes out of A's linked Portal B. Obviously it should conserve velocity and make sure it is pointing in the right direction, but I can figure the math out on my own. My question is on how to create a portal that can act as a trigger - I have looked through the wiki, and it seems that Shapes' ability to act as a trigger was removed in 0.8.0. I can provide some code, if it is needed, but I think the code I have at the moment won't help to answer this much.
tl,dr: How do I make a shape/body using love.physics that can act as a trigger when a body touches it?
Thanks in advance,
Selenaut
Portals and Teleporting the Player
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Portals and Teleporting the Player
Making a game in Lua without knowing Lua.
Re: Portals and Teleporting the Player
I think what you want is a sensor.
http://www.love2d.org/wiki/Fixture:setSensor
http://www.love2d.org/wiki/Fixture:setSensor
Re: Portals and Teleporting the Player
Hey seanmd, thanks for the reply.
That sounds like it should work. I'll continue posting my progress on getting these portals to work here. Hopefully soon I'll have a quick demo set up so people can check it out.
Thanks again,
Selenaut
That sounds like it should work. I'll continue posting my progress on getting these portals to work here. Hopefully soon I'll have a quick demo set up so people can check it out.
Thanks again,
Selenaut
Making a game in Lua without knowing Lua.
Re: Portals and Teleporting the Player
Alright, I have the portal class setup so that its fixture is a sensor. In the callback functions, how do I know which portal it's coming from?
At the moment, I have a table of portals, and I don't know how to tell which one was collided with, nor what collided with it. How do I get those?
Thanks,
Selenaut
At the moment, I have a table of portals, and I don't know how to tell which one was collided with, nor what collided with it. How do I get those?
Thanks,
Selenaut
Making a game in Lua without knowing Lua.
Re: Portals and Teleporting the Player
They're supposed to represent the same point in space, right? You may be overthinking the problem.
If you need to attach any arbitrary data to the fixture you can do so via fixture:setUserData(aTable)
If you need to attach any arbitrary data to the fixture you can do so via fixture:setUserData(aTable)
Re: Portals and Teleporting the Player
So I've set up a table for my Portal "class" called usrData. However, when I write:
and two objects collide, I get an error stating "attempt to index a nil value," by which it means that the one fixture's getUserData() didn't return a table. How can I avoid this?
Thanks,
Selenaut
Code: Select all
function beginCallback(fixture1, fixture2, contact)
if fixture1:getUserData().obj == "portal" then
--stuff
end
if fixture2:getUserData().obj == "portal" then
--other stuff
end
end
function endCallback(fixture1, fixture2, contact)
if fixture1:getUserData().obj == "portal" then
--more stuff
end
if fixture2:getUserData().obj == "portal" then
--still more stuff
end
end
Thanks,
Selenaut
Making a game in Lua without knowing Lua.
Re: Portals and Teleporting the Player
well, there are probably going to be objects without userdata unless you're explicitly setting them yourself. you'll need to do something like:
you could do something else to determine it's a table first, or you could just set the userData to "portal" rather than a table if you don't need anything else stored in it.
caveat: make sure you nil out the userdata when/if you finally destroy the object. I've found that they tend to stick around in memory even after destroying the fixture.
Keep on chuggin'
Code: Select all
if fixture1:getUserData() and fixture1:getUserData().obj == "portal" then
...
if fixture2 ...
caveat: make sure you nil out the userdata when/if you finally destroy the object. I've found that they tend to stick around in memory even after destroying the fixture.
Keep on chuggin'
Who is online
Users browsing this forum: Google [Bot] and 6 guests