HiddenMonk / Unity3DRuntimeTransformGizmo

A runtime transform gizmo similar to unitys editor so you can translate (move, rotate, scale) objects at runtime.
MIT License
707 stars 129 forks source link

Raycasts passing through the handles #24

Closed subhradeepc closed 4 years ago

subhradeepc commented 4 years ago

If we have a gizmo on an object , and there's another object right beside the previous one, while trying to drag the first object through its gizmo handle , we seem to select the next object as well.

Also , if two of the gizmo handles are overlapping, it becomes unpredictable which one gets selected

HiddenMonk commented 4 years ago

I dont seem to have the issue with with selecting objects behind while also selecting the handle. Can you maybe show me a video example? Can you also show me all the values you have set on your TransformGizmo since maybe you have something set in a way that might cause this issue. Try setting the gizmo to default values and see if problem is still there.

As for the overlapping gizmos, I guess it might be a little weird when for example the X handle is over the Z handle and you end up selecting the Z even though the X is closer to you, but for now I dont think its that much of an issue since youd probably have a camera the player could move around anyways, and I am not sure how hard it would be to make everything perfect =). Although maybe show a video of this issue as well in case there is a big issue with it that I'm not seeing.

Also make sure you have the latest version of the transformgizmo.

subhradeepc commented 4 years ago

Thanks a ton or getting back on this, turns out that i changed the GetTarget() function(that was being called from Update()) to OnMouseDown() in order to save calls every frame.

However, it would be really nice if you could explain why does that behavior occur, if we change it to OnMouseDown() [im pretty much a noob here] .

thnx again.

HiddenMonk commented 4 years ago

Probably just due to the order of things. OnMouseDown seems to be called before update, but the way things are set up, we need SetNearAxis to be called before GetTarget. GetTarget does a check if(nearAxis == Axis.None) before running, which would always be set to None in your case since it seems in TransformSelected we reset the nearAxis back to none when we call SetTranslatingAxis(transformType, Axis.None);, though I could be wrong =).