Load Proxy with Collision?

Can someone plz help me with the code for loading a collection proxy when the player comes into collision with my “portal” game object… plz help thx

This is a two part problem:

  1. Detect a collision between two collision objects
  2. Load a collection proxy

Can you already detect collisions between collision objects? If not, then you need to read the manual on physics and then do the following:

  1. Attach a collision object to your player. Possibly change the collision object type from Dynamic to Kinematic. Set its group to something meaningful (perhaps “player”). Set its mask to group you assigned to portal in step 2.
  2. Attach a collision object to your portal. Possibly change the collision object type from Dynamic to Kinematic. Set its group to something meaningful (perhaps “portal”). Set its mask to the group you assigned to player in step 1.
  3. Detect a collision_response in the on_message function of a script attached to the player.
  4. Check if the group of the object you collided with was of type “portal”

Like this:

function on_message(self, message_id, message)
    if message_id == hash("collision_response") then
        if message.group == hash("portal") then
           print("collided with portal")
        end
    end
end

Next step would be to load a collection proxy when the collision is detected. It should be as simple as doing like this:

function on_message(self, message_id, message)
    if message_id == hash("collision_response") then
        if message.group == hash("portal") then
           msg.post("url_of_your_proxy", "load")
        end
    elseif message_id == hash("proxy_loaded") then
        msg.post(sender, "enable")
    end
end
4 Likes

Notice that the loaded collection becomes a different physics world that your player will not collide with. If you want your player to continue into the new world you have to switch player game object at some point.

1 Like

This is described in the manual on collection proxies under the Worlds section.

Thx guys! That helped a lot… I’ll update when ready

1 Like

OK so now @britzl now I need help with unloading, do I need an entirely different script? because it’s saying that I haven’t loaded the level that I started in… UGH!

Could you please share some code of how you are unloading the collection and the exact error message you are getting? You should be able to unload from the same script. My guess is that you’re not trying to unload the correct collection.