Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
How to code for hidden or obstructed items / players into your game so the enemy doesn't see through walls and unable to interact with hidden/obstructed items: https://youtu.be/x_hpNYF7eEo |
||||
|
ps - this is good for realistic interactions of objects also so you cant access something underneath another item or through walls etc |
||||
|
you're video shows the code you built - are you going to post it here so we can use it for our projects? thanks! and always great work! |
||||
|
wrote: you're video shows the code you built - are you going to post it here so we can use it for our projects? thanks! and always great work! Thanks for the feedback. I like anyone who wants to use my code to enter it by themselves from the video as its way more satisfying then just copy and pasting someones else's work - that's so lazy IMO. We live in such a privileged society these days where the younger generation in particular expect too much for free all the time. They wont be getting that from me as I was brought up with a strong work ethic and gained everything only through hard work. A few minutes entering the code from the video is easy anyways so not a thing to be concerned about. Cheers, Robo. |
||||
|
I would hardly say I am lazy... nor where I live, is it all that privileged.... but you are right "not a thing to be concerned about." |
||||
|
wrote: I would hardly say I am lazy... nor where I live, is it all that privileged.... but you are right "not a thing to be concerned about." Don't take it personally count2feit - was not talking about you personally - just a general thing and I don't even know if your a young person anyway..so don't take it I was meaning yourself as I wasn't. Cheers and best regards. Robo |
||||
|
I will of course keep posting cool stuff for everyone to use and get the code themselves as its far more satisfying to do some work yourself and get it working... |
||||
|
wrote: you're video shows the code you built - are you going to post it here so we can use it for our projects? thanks! and always great work! I had a change in heart thanks to 'count2rfeit' and 'csp-games' and will post here the code for everyone to use. Before I had slight problem in that the collision point exactly matched the bounding box and hence caused some issues. Niko explained my problem that it needs to go further than just the bounding box slightly so I almost got it all right until 'csp-games' gave me the best code to do that. Here is the whole code: // viewing loot items check var startPos3D = ccbGetSceneNodeProperty(ccbGetActiveCamera(), "Position"); var endPoint3d = ccbGetSceneNodeProperty(ccbGetActiveCamera(), "Target"); var found = 0; var collPos = ccbGetCollisionPointOfWorldWithLine(startPos3D.x, startPos3D.y, startPos3D.z, endPoint3d.x, endPoint3d.y, endPoint3d.z); if (collPos != null) { collPos.x = collPos.x - ((startPos3D.x - collPos.x) * 0.01); collPos.y = collPos.y - ((startPos3D.y - collPos.y) * 0.01); collPos.z = collPos.z - ((startPos3D.z - collPos.z) * 0.01); var node = ccbGetSceneNodeFromName("cube"); if (ccbDoesLineCollideWithBoundingBoxOfSceneNode(node, startPos3D.x, startPos3D.y, startPos3D.z, collPos.x, collPos.y, collPos.z)) { var tmp = startPos3D.substract(collPos); var dist = tmp.getLength(); if (dist < 25) { found = 1; } }} if (found == 1) { ccbSetCopperCubeVariable("current", "cube"); var s = ccbGetSceneNodeFromName("cursor"); ccbSetSceneNodeProperty(s, "Visible", true); } else { ccbSetCopperCubeVariable("current", ""); var s = ccbGetSceneNodeFromName("cursor"); ccbSetSceneNodeProperty(s, "Visible", false); } enjoy - its works very nicely..and is going into my game. |
||||
|
The above code works fine actually but a cleaner adjustment I got from 'csp-games' is to replace: collPos.x = collPos.x - ((startPos3D.x - collPos.x) * 0.01); collPos.y = collPos.y - ((startPos3D.y - collPos.y) * 0.01); collPos.z = collPos.z - ((startPos3D.z - collPos.z) * 0.01); with collPos.x = startPos3D.x + (collPos.x - startPos3D.x) * 1.01; collPos.y = startPos3D.y + (collPos.y - startPos3D.y) * 1.01; collPos.z = startPos3D.z + (collPos.z - startPos3D.z) * 1.01; cheers and enjoy accurate obstruction checking in your game. |
||||
|
Thanks for sharing!
Are these JS functions ?? Or part of the CC Api? Never heard of them. I know string.length. But not getLength() |
||||
|
Good question - maybe it is part of CC internal functions.. I wish we had a few more like that actually but still able to do a lot already with existing API... |
|