c# - RTS touch camera movement -
i've been trying head around solution camera movement. these parameters needs work , thoughts had tried:
- camera movement / not world movement
- raycast move camera accurately along terrain
- touch movement works "grabbing" terrain towards or "pushing" away
- screen space world space not work because of angle of camera
so thoughts have lead me devise solution grab vector3 point ray hits ground under finger on fingerdown move camera in opposite direction real world distance between origin , movingpoint. if makes sense.
i'm pretty confused either confirm or deny idea , give clear way forward =)
i'm using asset called leantouch (brilliant piece of free scripts) touch inputs , far brain wants go: (lol)
var finger = lean.leantouch.fingers [lean.leantouch.fingers.count - 1]; var ray = finger.getray (); int layermask = (1 << 8); physics.raycast (ray, out hit, mathf.infinity, layermask); initialhit = hit.transform.position;
btw i'm working in unity , c#
ok, got it. nice smooth accurate camera movement, based on physical locations on map fingers touch screen.
using unityengine; public class simplecammove : monobehaviour { private raycasthit hit; private vector3 initialhit; private vector3 currenthit; private vector3 directionhit; private bool camactive; protected virtual void onenable() { // hook onfingerdown event lean.leantouch.onfingerdown += onfingerdown; // hook onfingerup event lean.leantouch.onfingerup += onfingerup; } protected virtual void ondisable() { // unhook onfingerdown event lean.leantouch.onfingerdown += onfingerdown; // unhook onfingerup event lean.leantouch.onfingerup += onfingerup; } public void onfingerdown(lean.leanfinger finger) { var ray = finger.getray (); //fires ray screentoworld @ finger pos using leantouch int layermask = (1 << 8); //ground layer camactive = true; if (physics.raycast (ray, out hit, 1500, layermask)) { initialhit = hit.point; } } protected virtual void lateupdate() { if (camactive == true) { var finger = lean.leantouch.fingers [lean.leantouch.fingers.count - 1]; var ray = finger.getray (); int layermask = (1 << 8); if (physics.raycast (ray, out hit, 1500, layermask)) { currenthit = hit.point; directionhit = (currenthit - initialhit); this.transform.translate(new vector3(-directionhit.x,0,-directionhit.z)); //camera stays @ same height. invert coords move camera correct direction } } } public void onfingerup(lean.leanfinger finger) { camactive = false; } }
Comments
Post a Comment