Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: charcoal on May 01, 2012, 01:34:55 AM

Title: [SOLVED] Using the mouse button to move an object to another position.
Post by: charcoal on May 01, 2012, 01:34:55 AM
 I am wanting to use the mouse to move an object in the xyz axes. I have created an object and added Get Mouse Button Down, Mouse Pick and Set Position. When I mouse click the screen to move the object to another position it moves to 0,0,0 in world space. I want the object to move to the postion where the position of mouse is when clicked on screen in xyz world space. I have created a variable called clickedPosition with vector3.
Title: Re: Using the mouse button to move an object to another position.
Post by: Alex Chouls on May 01, 2012, 01:47:39 AM
Take a look at the PlaymakerSamples\TestLab\Input\ClickMoveTo sample scene.

Does the object you're clicking on have a collider?
Title: Re: Using the mouse button to move an object to another position.
Post by: charcoal on May 02, 2012, 06:58:10 PM
Hi Alex,

Yes the object does have a collider. I want to click and drag the object anywhere in world space. I do not want to use a plane for the object to move on. I will have a look at the example you mentioned.

Title: Re: Using the mouse button to move an object to another position.
Post by: Alex Chouls on May 04, 2012, 09:29:26 PM
Did the example help?

Quote
I want to click and drag the object anywhere in world space. I do not want to use a plane for the object to move on.

Not sure what you mean... you have to translate the 2d click position into a 3d world position. Typically you use Mouse Pick or Raycast to get a 3d position in the world. The world can have any number of colliders, including Mesh Colliders, so you can make pretty much any clickable surface shape you want...
Title: Re: Using the mouse button to move an object to another position.
Post by: justifun on May 05, 2012, 09:38:16 AM
I think his ground is going to be either a terrain or some sort of non flat surface. 
Title: Re: Using the mouse button to move an object to another position.
Post by: charcoal on May 06, 2012, 12:53:39 AM
Hi Alex,

Yes I got the object to move along a plane using the mouse button. However I want to remove the plane altogether from the scene, and have the object move in world space all by itself using the mouse button. It seems I can only move an object if there is another object in the scene which it uses as a surface to move on.
Title: Re: Using the mouse button to move an object to another position.
Post by: Alex Chouls on May 06, 2012, 01:29:16 AM
You could use Screen To World Point:
https://hutonggames.fogbugz.com/default.asp?W570

You can use the mouse position for screen x and y, and some fixed distance for z. This moves the object on an imaginary plane in front of the camera... Is the what you're looking for?
Title: Re: Using the mouse button to move an object to another position.
Post by: charcoal on May 06, 2012, 09:23:14 PM
Hi Alex,

Screen to World Point is working, thanks. But each time I click to move the object it comes closer and closer to the camera and then it eventually it disappears. Also the object only moves if I click on the side of it, and I would like to smoothly drag it to another location. Any suggestions how to solve these problems would be appreciated. Ultimately I want to be able to create an multiple objects in world space with a click of the mouse, and then select them and move them about.
Title: Re: Using the mouse button to move an object to another position.
Post by: charcoal on May 14, 2012, 01:36:52 AM
I have got the object now moving freely in world space using Screen to World Point and Set Position. In Set Position I have set the Z vector to -5 to stop the object moving closer to the camera each time I click the mouse button. I have one problem left where I want to be able to click and drag the object, but I seem to be only able to click and place the object. Can anyone help?
Title: Re: Using the mouse button to move an object to another position.
Post by: jeanfabre on May 14, 2012, 02:57:05 AM
Hi,

 Two options, depending on if you want to use physics or not:

http://hutonggames.com/playmakerforum/index.php?topic=1286.0 (http://hutonggames.com/playmakerforum/index.php?topic=1286.0)

http://hutonggames.com/playmakerforum/index.php?topic=272.0 (http://hutonggames.com/playmakerforum/index.php?topic=272.0)

Bye,

 Jean
Title: Re: Using the mouse button to move an object to another position.
Post by: charcoal on May 22, 2012, 12:00:18 AM
Thanks Alex and Jean, it is working nicely now.