- Home /
Restricting "Drag GameObject" script to Z Axis?
I've found a good script that allows the player to drag GameObjects in the game around. However, I've had one problem with it. The object flies towards the camera, and I don't know how to stop it. Thankfully, the game I'm making is a 2D platformmer, and it only needs the objects to move along the Z axis. However, I do not know how to insert this into the script. Can someone help me with this?
The script is here: http://www.unifycommunity.com/wiki/index.php?title=DragObject
Answer by cjmarsh · May 16, 2011 at 08:01 AM
Change the yPos
variable to zPos
, addHeightWhenClicked
to addDistWhenClicked
And change -
myTransform.Translate(Vector3.up*addHeightWhenClicked);
to:
myTransform.Translate(Vector3.forward*addDistWhenClicked);
and every reference of -
myTransform.position.y
to
myTransform.position.z
I'm actually having a bit of the problem with the script itself now. The object first appears with no physics until I drag it for the first time. I feel like I might want to use an object that should be pushed before it can be dragged. Also, when I grab it, the object zooms into the centre of the screen, and requires a lot of mouse movement to get it to move a bit of the screen. Can I increase the sensitivity of this script?
Try tweaking the $$anonymous$$ove.* statements so that they all refer to z ins$$anonymous$$d of y.
I'm still having trouble getting the object to move with my mouse. I think it thinks the screen is larger than it is, and the object requires (much) more mouse movement than it should.
Your answer
Follow this Question
Related Questions
How would you override Editor object dragging? 0 Answers
Drag GameObject only in a specific area 1 Answer
Fixing "Drag GameObject with mouse" script 1 Answer
Drag GameObject with mouse in just one axis 2 Answers
Drag object 1 Answer