Jump to content
  • Advertisement

davejones

Member
  • Content count

    61
  • Joined

  • Last visited

Community Reputation

4 Neutral

About davejones

  • Rank
    Member

Personal Information

  • Role
    Programmer
  • Interests
    DevOps
    Education
    Programming

Recent Profile Visitors

829 profile views
  1. davejones

    Keep object in camera view

    When I say panning I mean dragging/swiping the camera out of view of the object I want to keep visible. I am trying to prevent the ability to drag/Swipe out of sight of the object in focus.
  2. https://gfycat.com/GlisteningUnselfishLeonberger
  3. davejones

    Keep object in camera view

    private void LateUpdate() { if (VisibleArea == null) { return; } Bounds b = VisibleArea.bounds; Vector3 world1 = _camera.ViewportToWorldPoint(Vector3.zero); Vector3 world2 = _camera.ViewportToWorldPoint(Vector3.one); Vector3 pos = transform.position; // move the camera so that the visible area is visible, if necessary // x axis if (world1.x > b.max.x) { pos.x -= (world1.x - b.max.x); } else if (world2.x < b.min.x) { pos.x += (b.min.x - world2.x); } // y axis if (world1.y > b.max.y) { pos.y -= (world1.y - b.max.y); } else if (world2.y < b.min.y) { pos.y += (b.min.y - world2.y); } transform.position = pos + (velocity * Time.deltaTime); velocity *= Dampening; } Looking at using this code as a way to keep a certain area visible at all times.
  4. davejones

    Keep object in camera view

    I am looking into keeping the panning within a bounded area so that the camera can't be panned out of sight of the object. Effectively use collisions. So when the camera is being panned it can only move so far until it is blocked. private void LateUpdate() { if (VisibleArea == null) { return; } Bounds b = VisibleArea.bounds; Vector3 world1 = _camera.ViewportToWorldPoint(Vector3.zero); Vector3 world2 = _camera.ViewportToWorldPoint(Vector3.one); Vector3 pos = transform.position; // move the camera so that the visible area is visible, if necessary // x axis if (world1.x > b.max.x) { pos.x -= (world1.x - b.max.x); } else if (world2.x < b.min.x) { pos.x += (b.min.x - world2.x); } // y axis if (world1.y > b.max.y) { pos.y -= (world1.y - b.max.y); } else if (world2.y < b.min.y) { pos.y += (b.min.y - world2.y); } transform.position = pos + (velocity * Time.deltaTime); velocity *= Dampening; } Looking at implementing the code above.
  5. davejones

    Keep object in camera view

    Thanks for the reply. I have added this script to the camera and I can still pan out of the objects sight. The target gameobject I have used is located in the centre of the 3D mesh.
  6. davejones

    Keep object in camera view

    The camera moves freely in that I can move out of sight of the mesh easily.
  7. davejones

    Keep object in camera view

    When I say going out of sight the target is a 3D mesh. So when I am rotating/panning, the camera can move completely out of sight of the mesh.
  8. I am using the rts cam script and was wondering if it was possible to stop the camera from going out of sight of an object. This set up is being developed in unity and is for a 3D game. The camera is being used to rotate, pan and zoom in/around an object. At the moment I can move out of sight of the object. Is there a way to block the camera from going out of sight of the object? I have seen multiple ways to keep an object in sight through the camera, however I am unsure which route to take. I have attached the script being used below. public class RTSCam : MonoBehaviour { private float dist; private float orbitSpeedX; private float orbitSpeedY; private float zoomSpeed; public float rotXSpeedModifier=0.25f; public float rotYSpeedModifier=0.25f; public float zoomSpeedModifier=5; public float minRotX=-20; public float maxRotX=70; //public float minRotY=45; //public float maxRotY=315; public float minZoom=3; public float maxZoom=15; public float panSpeedModifier=1f; // Use this for initialization void Start () { dist=transform.localPosition.z; DemoSceneUI.SetSceneTitle("RTS camera, the camera will orbit around a pivot point but the rotation in z-axis is locked"); string instInfo=""; instInfo+="- swipe or drag on screen to rotate the camera\n"; instInfo+="- pinch or using mouse wheel to zoom in/out\n"; instInfo+="- swipe or drag on screen with 2 fingers to move around\n"; instInfo+="- single finger interaction can be simulate using left mosue button\n"; instInfo+="- two fingers interacion can be simulate using right mouse button"; DemoSceneUI.SetSceneInstruction(instInfo); } void OnEnable(){ IT_Gesture.onDraggingE += OnDragging; IT_Gesture.onMFDraggingE += OnMFDragging; IT_Gesture.onPinchE += OnPinch; orbitSpeedX=0; orbitSpeedY=0; zoomSpeed=0; } void OnDisable(){ IT_Gesture.onDraggingE -= OnDragging; IT_Gesture.onMFDraggingE -= OnMFDragging; IT_Gesture.onPinchE -= OnPinch; } // Update is called once per frame void Update () { //get the current rotation float x=transform.parent.rotation.eulerAngles.x; float y=transform.parent.rotation.eulerAngles.y; //make sure x is between -180 to 180 so we can clamp it propery later if(x>180) x-=360; //calculate the x and y rotation //Quaternion rotationY=Quaternion.Euler(0, Mathf.Clamp(y+orbitSpeedY, minRotY, maxRotY), 0); Quaternion rotationY=Quaternion.Euler(0, y+orbitSpeedY, 0); Quaternion rotationX=Quaternion.Euler(Mathf.Clamp(x+orbitSpeedX, minRotX, maxRotX), 0, 0); //apply the rotation transform.parent.rotation=rotationY*rotationX; //calculate the zoom and apply it dist+=Time.deltaTime*zoomSpeed*0.01f; dist=Mathf.Clamp(dist, -maxZoom, -minZoom); transform.localPosition=new Vector3(0, 0, dist); //reduce all the speed orbitSpeedX*=(1-Time.deltaTime*12); orbitSpeedY*=(1-Time.deltaTime*3); zoomSpeed*=(1-Time.deltaTime*4); //use mouse scroll wheel to simulate pinch, sorry I sort of cheated here zoomSpeed+=Input.GetAxis("Mouse ScrollWheel")*500*zoomSpeedModifier; } //called when one finger drag are detected void OnDragging(DragInfo dragInfo){ //if the drag is perform using mouse2, use it as a two finger drag if(dragInfo.isMouse && dragInfo.index==1) OnMFDragging(dragInfo); //else perform normal orbiting else{ //apply the DPI scaling dragInfo.delta/=IT_Gesture.GetDPIFactor(); //vertical movement is corresponded to rotation in x-axis orbitSpeedX=-dragInfo.delta.y*rotXSpeedModifier; //horizontal movement is corresponded to rotation in y-axis orbitSpeedY=dragInfo.delta.x*rotYSpeedModifier; } } //called when pinch is detected void OnPinch(PinchInfo pinfo){ zoomSpeed-=pinfo.magnitude*zoomSpeedModifier/IT_Gesture.GetDPIFactor(); } //called when a dual finger or a right mouse drag is detected void OnMFDragging(DragInfo dragInfo){ //apply the DPI scaling dragInfo.delta/=IT_Gesture.GetDPIFactor(); //make a new direction, pointing horizontally at the direction of the camera y-rotation Quaternion direction=Quaternion.Euler(0, transform.parent.rotation.eulerAngles.y, 0); //calculate forward movement based on vertical input Vector3 moveDirZ=transform.parent.InverseTransformDirection(direction*Vector3.forward*-dragInfo.delta.y); //calculate sideway movement base on horizontal input Vector3 moveDirX=transform.parent.InverseTransformDirection(direction*Vector3.right*-dragInfo.delta.x); //move the cmera transform.parent.Translate(moveDirZ * panSpeedModifier * Time.deltaTime); transform.parent.Translate(moveDirX * panSpeedModifier * Time.deltaTime); } //for the camera to auto rotate and focus on a predefined position /* public float targetRotX; public float targetRotY; public float targetRotZ; public Vector3 targetPos; public float targetZoom; IEnumerator LerpToPoint(){ Quaternion startRot=transform.parent.rotation; Quaternion endRot=Quaternion.Euler(targetRotX, targetRotY, targetRotZ); Vector3 startPos=transform.parent.position; Vector3 startZoom=transform.localPosition; float duration=0; while(duration<1){ transform.parent.rotation=Quaternion.Lerp(startRot, endRot, duration); transform.parent.position=Vector3.Lerp(startPos, targetPos, duration); transform.localPosition=Vector3.Lerp(startZoom, new Vector3(0, 0, -targetZoom), duration); duration+=Time.deltaTime; yield return null; } transform.parent.rotation=endRot; transform.parent.position=targetPos; transform.localPosition=new Vector3(0, 0, -targetZoom); } */ /* private bool instruction=false; void OnGUI(){ string title="RTS camera, the camera will orbit around a pivot point but the rotation in z-axis is locked."; GUI.Label(new Rect(150, 10, 400, 60), title); if(!instruction){ if(GUI.Button(new Rect(10, 55, 130, 35), "Instruction On")){ instruction=true; } } else{ if(GUI.Button(new Rect(10, 55, 130, 35), "Instruction Off")){ instruction=false; } GUI.Box(new Rect(10, 100, 400, 100), ""); string instInfo=""; instInfo+="- swipe or drag on screen to rotate the camera\n"; instInfo+="- pinch or using mouse wheel to zoom in/out\n"; instInfo+="- swipe or drag on screen with 2 fingers to move around\n"; instInfo+="- single finger interaction can be simulate using left mosue button\n"; instInfo+="- two fingers interacion can be simulate using right mouse button"; GUI.Label(new Rect(15, 105, 390, 90), instInfo); } } */ }
  9. davejones

    AR kit plugin

    I used unity for AR because it seemed to be more ahead than unreal engine, but from what I have gathered unreal engine are catching up with AR. In terms of fixing the minor tracking problems I would't know where to start on how to fix them. How is it you know that unity has minor tracking problems in comparison to unreal engine?
  10. davejones

    3D template with touch inputs

    I apologise for not making it clear as to what engine I am using. I am using unity. I will look into mobile game examples in the asset store.
  11. I was wondering if there is a 3D game template with certain touch inputs. The touch inputs I want for the 3D game would be to pinch to zoom and panning and pinch to zoom and rotate. So in a nutshell the 2 desired touch inputs would be;- Pinch to zoom (2 fingers ideally) and pan (1 finger) - Pinch to zoom (2 fingers ideally) and rotate (1 finger).So I am in a 3D scene and I have a 3D cube in the scene. I want to be able to pinch to zoom and pan around the cube with one finger or pinch to zoom and rotate around the cube with one finger. Toggle between pinch to zoom (2 fingers) rotate (1 finger) or pinch to zoom (2 fingers) pan (1 finger). I have used a few plugins but I am struggling to get the desired functionality. .
  12. Hi, thanks for your response. I will look into using your recommendations, despite not using structs often.
  13. I am trying to communicate between 2 scripts that are in 2 different scenes. I start of in the home scene and than press a button that takes me into the main scene. When I go into the main scene I want a list of GameObjects to be disabled and another set of GameObjects to be enabled. - start off in the home scene- press a button that takes me to another scene (I can do this) - When I press button in home scene and enter main scene a list of gameobjects are disabled and another are enabled (struggling with this).
  14. I have been doing research into whether the arkit sdk can be used to build to android in unity? I can't seem to find a conlcusive answer yet. I am curious to find out because googles arcore sdk can be built to ios so I was wondering if the arkit plugin could be used on android devices.
  15. davejones

    3ds max reduce poly count

    I have tried this and it works. I can now reduce the polygon count and than collapse the modifier. Thanks for the recommendation.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!