playMaker

Author Topic: [SOLVED] Using the mouse button to move an object to another position.  (Read 5558 times)

charcoal

  • Playmaker Newbie
  • *
  • Posts: 6
 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.
« Last Edit: May 22, 2012, 10:40:20 AM by Alex Chouls »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3998
  • Official Playmaker Support
    • LinkedIn
Re: Using the mouse button to move an object to another position.
« Reply #1 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?

charcoal

  • Playmaker Newbie
  • *
  • Posts: 6
Re: Using the mouse button to move an object to another position.
« Reply #2 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.


Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3998
  • Official Playmaker Support
    • LinkedIn
Re: Using the mouse button to move an object to another position.
« Reply #3 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...

justifun

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 280
Re: Using the mouse button to move an object to another position.
« Reply #4 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. 

charcoal

  • Playmaker Newbie
  • *
  • Posts: 6
Re: Using the mouse button to move an object to another position.
« Reply #5 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.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3998
  • Official Playmaker Support
    • LinkedIn
Re: Using the mouse button to move an object to another position.
« Reply #6 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?

charcoal

  • Playmaker Newbie
  • *
  • Posts: 6
Re: Using the mouse button to move an object to another position.
« Reply #7 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.

charcoal

  • Playmaker Newbie
  • *
  • Posts: 6
Re: Using the mouse button to move an object to another position.
« Reply #8 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?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Using the mouse button to move an object to another position.
« Reply #9 on: May 14, 2012, 02:57:05 AM »

charcoal

  • Playmaker Newbie
  • *
  • Posts: 6
Re: Using the mouse button to move an object to another position.
« Reply #10 on: May 22, 2012, 12:00:18 AM »
Thanks Alex and Jean, it is working nicely now.