Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Announcements and Showcase
Hidden items / players

Robo
Guest
Quote
2021-01-11 10:48:33

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


Robo
Guest
Quote
2021-01-29 02:11:41

ps - this is good for realistic interactions of objects also so you cant access something underneath another item or through walls etc


count2rfeit
Registered User
Quote
2021-01-29 02:57:42

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!


Robo
Guest
Quote
2021-01-30 02:40:42

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.


count2rfeit
Registered User
Quote
2021-01-30 04:34:43

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."


Robo
Guest
Quote
2021-01-30 11:29:04

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


Robo
Guest
Quote
2021-01-30 12:12:22

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...


Robo
Guest
Quote
2021-02-15 00:08:40

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.


Robo
Guest
Quote
2021-02-15 00:16:32

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.


csp-games
Guest
Quote
2021-02-15 04:58:06

Thanks for sharing!



var tmp = startPos3D.substract(collPos);
var dist = tmp.getLength();


Are these JS functions ?? Or part of the CC Api?

Never heard of them. I know string.length. But not getLength()


Robo
Guest
Quote
2021-02-15 07:43:35

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...


Create reply:


Posted by: (you are not logged in)


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


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






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