Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
How to check the collision between two points?

dekon_17
Registered User
Quote
2021-09-25 10:00:22

So, I have a trouble with this script for a while by now, and I still can't deal with it. The point of this script was to check collision between two nodes, using their absolute position (this is needed for me), and if there is no collision - it should've draw the rectangle at the end node. If there was a collision, the rectangle should've been placed at the collision position.
However, for some reason the script worcs incorrectly, and I don't know why. Here it is:
var SP = ccbGetSceneNodeProperty(this.StartPoint, "PositionAbs");
var EP = ccbGetSceneNodeProperty(this.EndPoint, "PositionAbs");
var Col = ccbGetCollisionPointOfWorldWithLine(SP.x, SP.y, SP.z, EP.x, EP.y, EP.z);
if (Col == null)
{
var Pos2D = ccbGet2DPosFrom3DPos(EP.x, EP.y, EP.z);
}
else
{
var Pos2D = ccbGet2DPosFrom3DPos(Col.x, Col.y, Col.z);
};
ccbDrawColoredRectangle(0x77ff0000, Pos2D.x - 100, Pos2D.y - 100, Pos2D.x + 100, Pos2D.y + 100);

If you can understand, what is the problem, can you please tell me what's wrong?


sven
Registered User
Quote
2021-09-25 12:14:49

Code looks OK but:

Draws a colored rectangle. This function can only be used inside a frame event function which must have been registered with ccbRegisterOnFrameEvent().


dekon_17
Registered User
Quote
2021-09-25 12:59:07

Sven wrote:
Draws a colored rectangle. This function can only be used inside a frame event function which must have been registered with ccbRegisterOnFrameEvent().

Well, this means that it is more strange, because the code I left here is a part from my full code, and this is being registered. If the code is fine, then I don't know what can be possible reason for this to work bad (not work).


sven
Registered User
Quote
2021-09-25 13:04:52

What exactly doesnt work ?
does it place rectangle in wrong location or doesnt draw it at all ?

If i tested it and registred function then it did draw a rectangle at collision point.


sven
Registered User
Quote
2021-09-25 13:07:31



function onFrameDrawing()
{


var kuup=ccbGetSceneNodeFromName("Camera1" );
var kuup1=ccbGetSceneNodeFromName("kuup" );


var SP = ccbGetSceneNodeProperty(kuup, "PositionAbs");
var EP = ccbGetSceneNodeProperty(kuup1, "PositionAbs");
var Col = ccbGetCollisionPointOfWorldWithLine(SP.x, SP.y, SP.z, EP.x, EP.y, EP.z);
if (Col == null)
{
var Pos2D = ccbGet2DPosFrom3DPos(EP.x, EP.y, EP.z);
}
else
{
var Pos2D = ccbGet2DPosFrom3DPos(Col.x, Col.y, Col.z);
};
ccbDrawColoredRectangle(0x77ff0000, Pos2D.x - 100, Pos2D.y - 100, Pos2D.x + 100, Pos2D.y + 100);


}

ccbRegisterOnFrameEvent(onFrameDrawing);




dekon_17
Registered User
Quote
2021-09-25 13:45:53

Huh, looks like I did it in other way, that's why it wasn't been working. I mean, I used this:
behavior_collision.prototype.onAnimate = function(node, timeMs)
{
if (this.LastTime == null)
{
this.LastTime = timeMs;
return false
}

Anyway, I'll try to use your variant, don't know will it work though.


dekon_17
Registered User
Quote
2021-09-25 13:55:53

Strange, I attempted to use this in behavior, but it doesn't work. Maybe because, obviously, it is a behavior...


sven
Registered User
Quote
2021-09-25 13:55:53

Variant i used is from coppercube manual.. so it must be the correct way for doing it :D

https://www.ambiera.com/coppercu...


dekon_17
Registered User
Quote
2021-09-25 13:56:27

lol


just_in_case
Moderator
Quote
2021-09-26 07:09:00

yeah, if you are into scripting then you should always check the javascript API in the documentation, it has got so many examples.


dekon_17
Registered User
Quote
2021-09-26 12:19:23

just_in_case wrote:
yeah, if you are into scripting then you should always check the javascript API in the documentation, it has got so many examples.

I am actually doing so. If you mean the JavaScript scripting reference thing.


dekon_17
Registered User
Quote
2021-09-28 14:08:58

Edit: this problem is solved. But the new one appeared lol


I tried to make the script working, but, uhh...
It says that it "Could not find property: provided scene node is invalid" (or something like that). I don't understand what am I doing wrong, but this time I'll leave the script here:
/*
<behavior jsname="behavior_aim" description="Look how bullet will fly">
<property name="StartPoint" type="scenenode"/>
<property name="EndPoint" type="scenenode"/>
<property name="Crosshair" type="texture"/>
<property name="Crosshair_Size_X" type="float"/>
<property name="Crosshair_Size_Y" type="float"/>
</behavior>
*/

behavior_aim = function()
{
};

behavior_aim.prototype.onAnimate = function()
{
function onFrameDrawing()
{
var SP = ccbGetSceneNodeProperty(this.StartPoint, "PositionAbs");
var EP = ccbGetSceneNodeProperty(this.EndPoint, "PositionAbs");
var Col = ccbGetCollisionPointOfWorldWithLine(SP.x, SP.y, SP.z, EP.x, EP.y, EP.z);
if (Col == null)
{
var Pos2D = ccbGet2DPosFrom3DPos(EP.x, EP.y, EP.z);
}
else
{
var Pos2D = ccbGet2DPosFrom3DPos(Col.x, Col.y, Col.z);
};

ccbDrawColoredRectangle(0x77ff0000, Pos2D.x - 100, Pos2D.y - 100, Pos2D.x + 100, Pos2D.y + 100);
}
ccbRegisterOnFrameEvent(onFrameDrawing);
}



nbaever3
Registered User
Quote
2021-10-19 21:05:45

Thanks for sharing the solution I was also facing this issue since many days but finally i got the solution. Thank You so much
https://spicemoneylogin.in https://myfiosgateway.one


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "I?ternational" (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