Need some advice on how you guys might go about implementing something…
Here is a mock up of a piece of UI I am trying to build in my game. Each point along the ring is a click and drag slider point.
The center object (a planet) will be in 3d, but the sliders don’t necessarily need to be, they just need to stay positioned correctly relative to the planet. I am assuming I would need to implement this using in game 3d objects rather than the GUI system (which seems too limited for something like this). Any examples, even high level, of how this might be accomplished would be very helpful.
Even an example of how to turn a 3d object into a button would definitely get me started.
Check the Camera.ScreenToWorldPoint and Physics.Raycast function docs. That should get you going. You go a raycast from ScreenToWorldPoint(Input.mousePosition) into the world and then test if you hit your “GUI” objects. If you do, send the object a message (or call a function directly) that does whatever the button should do.
That definitely solves the mouse/touch input problem - thanks a ton.
Now as far as creating the rotary dial like movement that I am after… any suggestions or existing examples on how I might implement that? Any tutorials or examples that demonstrate constraining dragging an object along a circular path?
sorry for reviving this thread, but I am having a very similar problem.
I haven’t found any references on how to make a dial like control like this.
One of my attempts have been to find a drag amount on the x axis in screen space. But this hasn’t been good enough to get that dial like effect. Here’s a sample of what I did:
(sorry about the formatting)
function OnMouseDown()
{
// ...
var lastX;
var thisX;
var deltaX;
mouseDownPos = Vector3(Input.mousePosition.x,Input.mousePosition.y, 0);
thisX = mouseDownPosition.x;
//if the cursor hasn't moved then ignore the transform
while(mouseDownPos == Vector3(Input.mousePosition.x,Input.mousePosition.y, 0))
{
yield;
}
if(mouseDownPos != Vector3(Input.mousePosition.x,Input.mousePosition.y, 0))
{
while(Input.GetMouseButton(0))
{
//spin
lastX = thisX;
thisX = Input.mousePosition.x;
deltaX = lastX - thisX;
rotateValue = deltaX * rotSpeedMultiplier;
transform.Rotate(Vector3(0,rotateValue,0));
yield;
}
}
//....
}
the problem with this method is that it doesn’t really act like a dial. It does work correctly when dragging left and right, but when you get to the part of the object where you would expect to be able to drag up to rotate the object it doesn’t do anything since I’m not getting any y drag data.
If anyone has some insight on this type of problem, please let us know =)
After setting a target lookAt point with a RaycastHit.point object. I made sure that the point was at the same y as my object so it kept pointing in the correct plane.
Here’s the code for any future reference. Or feedback on how I can improve it.
(Once again, sorry for the formatting)
function OnMouseDown()
{
mouseDownPosition = Vector3(Input.mousePosition.x, Input.mousePosition.y, 0);
//if the cursor hasn't moved then ignore the transform
while(mouseDownPosition == Vector3(Input.mousePosition.x,Input.mousePosition.y, 0))
{
yield;
}
if(mouseDownPosition != Vector3(Input.mousePosition.x,Input.mousePosition.y, 0))
{
while(Input.GetMouseButton(0))
{
//cast a ray from the player camera to the direction of the mouse cursor
var ray = camera.main.ScreenPointToRay(Input.mousePosition);
var hit : RaycastHit;
//checks for hits within detectGUIDistance
if(Physics.Raycast(ray,hit,detectGUIDistance))
{
var targetX = hit.point.x;
var targetZ = hit.point.z;
var targetY = transform.position.y;
var target = Vector3(targetX, targetY, targetZ);
transform.LookAt(target);
}
yield;
}//end while
}//end if
}//end if
}
}