Ambiera ForumDiscussions, Help and Support. |
|
| [ 1 2 3 ] Page 1 of 3 |
|
|||||
|
Hello! I have something to ask, wich is about this peice of code: var anti2 = ccbGetCopperCubeVariable('anti2'); var player = ccbGetSceneNodeFromName('player'); var node = ccbGetSceneNodeFromName('cubeMesh2'); var posPlayer = ccbGetSceneNodeProperty(player, 'Position'); var posOfNode = ccbGetSceneNodeProperty(node, 'Position'); var mousePosX = ccbGetMousePosX(50); var mousePosY = ccbGetMousePosY(50); var actualPos = ccbGet3DPosFrom2DPos(mousePosX, mousePosY); if(anti2 === 1) { ccbSetSceneNodeProperty( node, 'Position', actualPos1 ); } else { print('Hello world!') }; //end when it executes, it almost perfectly sets the position. The reason i said 'almost' is becouse it set's the position really far away from the player, and i can only see it in just a few pixels. So, my question is: How to reduce this large distance between the player and the scene node? |
||||
|
Hi, i would like to help. can you please explain what you want to achieve with the script? |
||||
|
Thank you! Well, i am trying to make a gun that can drag objects, like 'cubeMesh2' in the script. |
||||
|
So, there are a bunch of things here. First: there's no point in having any parameters in ccbGetMousePosX and ccbGetMousePosY. That is, at least, according to documentation. Second: the reason that your position is far away from your character is because ccbGet3DPosFrom2DPos will... don't know how to explain this better, return you a 3D position from 2D, limited by the FarPlane parameter of your active camera. By default, it is set to 3000, which means that the end position will be around 3000 units away from your position. This isn't really a hard fix. By that I mean: ... Not sure I fully understood your intentions, so, might not be the required result, I don't know. |
||||
|
Thank you for your help, this is what i needed! As for the code, i should have learned about JavaScript's 'Math.()' function... Anyways, have a good day! |
||||
|
I'm interested with how it works, winterdev or dekon, can you help me out |
||||
|
Well, it's not really all that complicated, Monks. Basicaly, when the "anti2" variable is set to 1, it moves a scene node (in this case - cubeMesh2) in the direction of your mouse cursor, relative to the player character. Think of a gravity gun from Half-Life 2, but more primitive. This is sort of the same thing. |
||||
|
Oh i see, this is a cool concept, how do I implement it, should I execute as Javascript |
||||
|
@Dekon? |
||||
|
Well, yes, you can either use "Execute JavaScript" action, or a separate action/behavior. Your choice. |
||||
|
forgive me, my scripting isn't good, so i don't know what to actually implement |
||||
|
I have found another solution (after learning more about the Math.example(); function in javascript) : //start: var anti2 = ccbGetCopperCubeVariable('anti2'); var player = ccbGetSceneNodeFromName('player'); var node = ccbGetSceneNodeFromName('cubeMesh2'); var posPlayer = ccbGetSceneNodeProperty(player, 'Position'); var mousePosX = ccbGetMousePosX(50); var mousePosY = ccbGetMousePosY(50); var actualPos = ccbGet3DPosFrom2DPos(mousePosX, mousePosY); var offset = 30; if(anti2 === 1) { actualPos.x = posPlayer.x + (actualPos.x - posPlayer.x) * (offset / Math.sqrt(Math.pow(actualPos.x - posPlayer.x, 2) + Math.pow(actualPos.y - posPlayer.y, 2) + Math.pow(actualPos.z - posPlayer.z, 2))); actualPos.y = posPlayer.y + (actualPos.y - posPlayer.y) * (offset / Math.sqrt(Math.pow(actualPos.x - posPlayer.x, 2) + Math.pow(actualPos.y - posPlayer.y, 2) + Math.pow(actualPos.z - posPlayer.z, 2))); actualPos.z = posPlayer.z + (actualPos.z - posPlayer.z) * (offset / Math.sqrt(Math.pow(actualPos.x - posPlayer.x, 2) + Math.pow(actualPos.y - posPlayer.y, 2) + Math.pow(actualPos.z - posPlayer.z, 2))); ccbSetSceneNodeProperty(node, 'Position', actualPos); } else { print('Hello world!'); }; //end this one works a little...weird, but becouse it is in a game that tells a story, we can just blame it on the person the player is controlling not being able to handle the device properly (by device i mean that gun i wanted to make). |
||||
|
hi winterdev, i executed the script but it does not work, how do you do it. |
||||
|
are there errors, or it just does not work and theres no message on the debug console? if the first is the case, check if the object you wish to drag is named 'cubeMesh2' but you can just edit that in the code if you do not want that name. also check if the camera node that is currently active is named: 'player'. you also require an existing coppercube variable called: 'anti2'. you can set it with any behaviour, but 'Before first drawing do something' is the best option i think. if you chose that, go te 'Execute javascript' and set that variable and set it equal to 1. this way, it should work |
||||
|
it should work like this: https://www.youtube.com/watch?v=... |
||||
| [ 1 2 3 ] Page 1 of 3 |
|
|