Jump to content

The problem in the coordination of the object


DigitalHilsone
 Share

Recommended Posts

Dear users! I have a problem:
 
There is a field with the object. Clicking on the field, the object must move to a clique. All it does. But on the second click, the movement is entirely different coordinates.

 

 

What to do?
 
Here is the template code:
var createScene = function () {    var scene = new BABYLON.Scene(engine);    // setup environment    var light0 = new BABYLON.PointLight("Omni", new BABYLON.Vector3(0, 10, 20), scene);var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0, 0, new BABYLON.Vector3(10, 10, 0), scene);    camera.setPosition(new BABYLON.Vector3(-10, -10, -30));    camera.attachControl(canvas, true);    // Impact impostor    var impact = BABYLON.Mesh.CreatePlane("impact", 1, scene);    impact.material = new BABYLON.StandardMaterial("impactMat", scene);    impact.material.diffuseTexture = new BABYLON.Texture("textures/impact.png", scene);    impact.material.diffuseTexture.hasAlpha = true;    impact.position = new BABYLON.Vector3(0, 0, -0.1);    //Wall    var wall = BABYLON.Mesh.CreatePlane("wall", 20.0, scene);    wall.material = new BABYLON.StandardMaterial("wallMat", scene);    wall.material.emissiveColor = new BABYLON.Color3(0.5, 1, 0.5);    //When pointer down event is raised    scene.onPointerDown = function (evt, pickResult) {        // if the click hits the ground object, we change the impact position        if (pickResult.hit) {BABYLON.Animation.CreateAndStartAnimation("anim", impact, "position", 30, 30,impact.position, impact.position.add(new BABYLON.Vector3(pickResult.pickedPoint.x, pickResult.pickedPoint.y, 0)),0);            //impact.position.x = pickResult.pickedPoint.x;            //impact.position.y = pickResult.pickedPoint.y;        }    };    return scene;}

 

Link to comment
Share on other sites

Hiya D! Good to see you again.

Take a look at this...

http://playground.babylonjs.com/#17ADNM

Open your JS console and watch the log messages as you click-around. 

The pickedPoints are correct, but the whereto numbers are garbage.  This might indicate that your "add" is broken somehow.  You might also notice.... that the first click... works correctly.  This might indicate that some value is "accumulating"... not being cleared-out between picks/adds.  Maybe.  :)

That's all I have had time to investigate so far, sorry.  This should help with your troubleshooting, though.  Good luck!

Link to comment
Share on other sites

Hi DH,
 
Welcome to the forum.  I'm not at all clear as to what result you are looking for.  Your mesh appears to be animating correctly adding the x and y mouse position on the pointerdown event using impact.position.add 
 
However, if you use the original code below - which you remarked out - the mesh moves to the pointer x and pointer y position which appears to be the animation you describe as what you want to happen.
        if (pickResult.hit) {
            impact.position.x = pickResult.pickedPoint.x;
            impact.position.y = pickResult.pickedPoint.y;
        }

 

So your mesh is currently animating exactly as you've written by adding the pointer x and y pos. to vector3.  So unfortunately, I'm not sure what the problem is since everything is working correctly as it is written.  The math is calculating correctly and the new position for vector3 is correct on every pointerdown event.  If there is a different behavior you're seeking, please describe.

Link to comment
Share on other sites

  • 4 weeks later...
On 4/17/2015 at 1:16 AM, jahow said:

Hey,

This should work: http://playground.babylonjs.com/#17ADNM#1

I removed the part where you add the current mesh position to the pickedpoint to determine the "whereto" vector. Now whereto is equals to the pickedpoint, and it seems to work fine.

Thank you very much! All the best and good luck!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...