Halo Forge style picking up objects

How should I go about making it so I will be able to click on an object and carry it around while controlling a flying camera unitil it is released? Something similar to how forge works in some of the halo games. I figured it would have something to do with raycasting and such but still can’t wrap my head around it.

1 Answer

1

You could use raycasting. Also HitRayCast, when the HitRay collides with an object while pressing and holding the left mouse button, have that objects transform.position follow the position of your mouse which you will need to find where that is in world space. You will just have to extensively look at RayCast and HitRayCast to find some functions that offer this. Other than that it is pretty straight forward.

Or actually you don’t even have to have it follow the mouse, just making it follow your flying cameras x and y position, assuming Z is the depth, which you will make it like transform.position.z + distanceBetweenCamera
Something like this could work too.

This will also help. http://answers.unity3d.com/questions/381228/moving-an-object-from-point-a-to-point-b-by-the-dr.html

If there was a code it could of helped. I guess I just need to know how to click on an object and send it to the location of another gameobject

Thank you for explaining, that is all I needed to know. Makes more sense now to me.

Oh one more question I got it working but how do I access other cameras besides just the main camera camera? Camera.main.ScreenPointToRay

Make sure only one camera in the scene is active, Unity will automatically go to the active one. So, you have: Main Camera Camera2 Camera.main.active = false // turns it off //don't forget to turn off audio source as well. //then turn on the other camera GameObject.Find('Camera2').active = true // not sure if setactive,active, or enable. Check docs for accuracy. Also, not sure if you will need to do GetComponent(Camera), just try and see which works.