Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
Block linepick?

2023-05-18 18:52:52

What method do people use to block linepicks from going through walls?

I can turn on the light from outside the room:


I've got a couple ideas how to try and go about it but I was wondering what the community does?

I'm pretty much using the code example for ccbDoesLineCollideWithBoundingBoxOfSceneNode() but with an array of "pickable" objects.

Registered User
2023-05-18 20:58:36

Good question.
I would very much like to know the answer as well.

2023-05-18 21:42:34

There seems to be 2 Questions that you are asking, first one is blocking the line pick, and second one is how to stop prevent from turning on and off the light if you are outside the room.

First of all you don't need an array of pickable object, and collision API is a bit resource heavy so might affect the performance of your game, but if you want that the line don't pick the item behind a wall, then yeah, you can simply check the collision with of the bounding box of the scene node, but as you won't be able to control the size of the bounding box it might be possible that your switch bounding box will pop out of the wall, so it may still get trigger.

you can instead check the ray with the world, and if it collides then you can check if the returned collision point is in the radius of the switch, you can control that radius in your script, soil it gives you more control over your game. but as I said it can be resource intensive.

what you can do to stop clicking the switch if outside the room is use on proximity behavior which is similar to the radius method like I suggested above and you can allign or position the proximity sphere or box inside the room, and can check for a variable if player is in proximity set the variable true, and when clicked on the switch check for that variable, if the variable is true then only execute the light action otherwise you can execute something else or so some other message like you are far away from the switch go closer to turn the lights On.

there can be other alternative ways, but if you want to do it with inbuilt behaviors then it will be much easier to setup.

2023-05-18 22:17:46


Appreciate the answer. The first solution you offered was one I had already considered but it's good to know I was on the right track with it. I made the level as one model in Blender and am wondering if the bounding box detection is affected by being inside the model as I can clearly see the box around the model's edges but not inside the model along the walls. Would making the level out of modular pieces so they have individual bounding boxes make checking the collision point with the world unnecessary?

2023-05-18 23:08:52

Yeah seems making a level out of one mesh is a bad idea for this engine unless you want to add your own box colliders all over the place and double up some geometry. Basically all I had to do was add a "blocking" mesh (and code) to block the linepick from detecting the switch. I am still going to redo my level with modular pieces as that it easier to code and requires less geometry in the end. Modular design is your friend, kids. Thanks.

2023-05-20 08:06:15

why don't use just use on proximities, or create virtual proximities, by simply adding dummy nodes, at the position where you want the proximities to be. you don't even need linepick or collision check, it will be much faster as well, and will work with objects, without collision, like with animated meshes and all.

You can totally skip using the line pick, the proximity method will work just fine either if it's a big single mesh, or chunk of multiple modular meshes. This will work fine on everything.

2023-05-20 18:23:00

I'd rather use a linepick with two arrays than to go through the trouble of adding a bunch of behaviors and scaling proximity boxes. I've also seen issues with On Proximity causing the player to start running forward and never stop even without pressing a button. That's not to say On Proximity is bad or without its uses. My problem was my level's mesh didn't react as I had expected. I assumed the CC's linepick functions would detect that wall but it seems being inside the bounding box of the mesh causes issues with that. Thanks for the advice though.

2023-05-20 19:36:50

I mean you don't have to do it in behaviors, you can do it in scripting, by creating a radius around the object. And the auto running bug is not related to on proximity at all, your player will keep running, if you are running in game and simply tab out of the game, and if you go back to the game, you will find that your player will keep running.

Still, if you want to use line picks only. Then here is how you can do it. this is how I implemented the collision detection in my 2D TopDownShooter, behavior.

cast a ray in the direction of the object, generally from the player position to the player-facing position, and instead of checking the collision with the bounding box of the wall. Check the collision with the world, if there is a collision, it will return you a collision point.
Now from the returned collision point, cast a very small ray in the direction of player, and check if that ray collides with the bounding box of the player.

What it will do is, it will first grab the actual point at the wall, from where the collision will happen and then it will check if the player is colliding with the wall by checking the collision of the small ray casted from wall with the bounding box of the player.

You can see in this unlisted video, the bullets, AI Enemy (pink), and AI(ally) can avoid the obstacles or bullets getting destroyed by checking the line pick collision with the scattered cube mesh in the scene. This uses the line pick method.

here are some videos on my YT channel:-

this one is not line picking but a basic pathfinding or chase implementation

Create reply:

Posted by: (you are not logged in)

Enter the missing letter in: "Inter?ational" (you are not logged in)




Possible Codes

Feature Code
Link [url] [/url]
Bold [b]bold text[/b]
Image [img][/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]



Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact