playMaker

Author Topic: How do I make it so that when you click and hold and move it around? [Solved]  (Read 2825 times)

NyxLabs

  • Playmaker Newbie
  • *
  • Posts: 4
Hi
I'm making the prototype of a game and I want to be able to click and hold and object, and for that object to be moved with the mouse as long as you hold the click.

My current problem is that the object teleports when I click it (after I've set the object so that it follow my mouse) and then it starts to follow my mouse off camera.

Does this make sense or do I need to explain more?
« Last Edit: March 06, 2015, 07:02:03 PM by NyxLabs »

IEP

  • Playmaker Newbie
  • *
  • Posts: 9
  • Computer Arts
do you want that object to follow your camera or mouse ? cause you can move an object with a camera which have a "Mouse Camera" component, then you should just parent and disparent (Setting parent Field to "Empty") object to camera ... and then it moves with the camera which is moving with your mouse ! (but if you wanted camera still and object moving i dont have any idea for certain ^-^ ).

NyxLabs

  • Playmaker Newbie
  • *
  • Posts: 4
I want the camera to not move and to move the object with the mouse.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
The idea is to have 2 states, one waiting for the mouse button to be pressed, and one waiting for it to be released.

State 1 (wait for mouse down) transitions to State 2 (wait for mouse up) which transitions back to State 1.

In State 2 you just use a Mouse Pick or something and get the position, then use Set Position to put the object at that position. Get Mouse Button with Bool Test will get the transitions working for you. Use a 3rd state with Next Frame Event if you get infinite loop errors. The movement/following would depend on how you want it setup, but thats basically all that is involved.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

NyxLabs

  • Playmaker Newbie
  • *
  • Posts: 4
I already have it so that when you have your mouse over it and you click it changes state. My problem is that when I click it it teleports elsewhere in the level. I am using Set Position and using Get Mouse X and Get Mouse Y to get the position of the mouse.

The object does follow the mouse. The problem is that teleports off camera when it start following the mouse.

And Mouse Pick doesn't work for getting the mouse's position.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
The Mouse Position is a screen space property. If you want something to follow the mouse then you need to project a raycast from a point on the screen to world space and record where it intersects with a given layer to get a proper "world position of the mouse".

So, Mouse Pick is the way to go. Choose an appropriate layer for your floor, store the HitPoint, use that for the target position for the GameObject.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

NyxLabs

  • Playmaker Newbie
  • *
  • Posts: 4
Thanks a ton Lane. That was just what I need. ;D