Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Camera bug, speed difference [edited]

Discussion in 'Editor & General Support' started by Fissll, Feb 7, 2016.

  1. Fissll

    Fissll

    Joined:
    Jan 30, 2015
    Posts:
    70
    Good day everyone!
    I am currently working on my first "proper" game and a couple of weeks ago I looked at the camera control.
    I wanted a similar camera system to clash of clans and started research.

    As it turned out, nobody has ever done something like that (at least google doesn't give me any good results)
    and because I don't have the money to buy a camera system from the asset store or something like that,
    I decided to build it myself ... "shouldn't be too hard" I thought to myself.

    How wrong I was :eek: ...

    I started the script like a complete idiot and had many issues.
    Panning getting faster when the resolution changes etc. ...
    But after some versions of the script (it went through a lot of changes in a short time span ^^),
    I finally put together something neat.

    It works super great in the editor and with Unity Remote but the crazy part now is,
    that the panning is slower when I build it to an android device.
    It just doesn't make any sense :(.

    Now, to spare myself from horrible nightmares and frustration, I release this annoying thing into the world.
    It would be super awesome if someone could help me with this.
    And since there are so few orthographic camera systems out there,
    you can do what you want with this unity package ...
    just don't sell it or something like that.

    Edit: The package was build in 5.2 if anyone needs to know.

    Thanks in advance :D
     

    Attached Files:

    Last edited: Feb 7, 2016
  2. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I don't think it's funny joking about suicide though.
    Edited your title.

    In any case, learn about Time.deltaTime
     
    Fissll and Teila like this.
  3. Fissll

    Fissll

    Joined:
    Jan 30, 2015
    Posts:
    70
    I'm sorry. I didn't mean to offend anybody.:oops:
    Anyway, what do you mean with delta time?
    I use delta time all the time and I even tried using FixedUpdate instead of Update.
    Like I said, in the editor it runs great and precise (although with a bit of lag when using Unity Remote)
    but when I build it to the android device, it is more than twice slower than in the editor :(
     
  4. Fissll

    Fissll

    Joined:
    Jan 30, 2015
    Posts:
    70
    bump

    @hippocoder what exactly do you mean with "learn about Time.deltaTime"?
    I think I tried everything now (multiplying and dividing by Time.deltaTime and Touch.deltaTime)
    and still nothing works ... I'm slowly going mad again.

    Like I said, my current solution works great with mouse input and with Unity Remote
    but NOT when I build it to the android device and I also don't really want to do some dumb fix like
    Code (CSharp):
    1. Input.GetTouch(0).deltaPosition / (Input.GetTouch(0).deltaTime*50.0f)
    because that feels really hacky.

    Is there really nobody who can help me with this?
     
  5. Fissll

    Fissll

    Joined:
    Jan 30, 2015
    Posts:
    70
    Ok @hippocoder I finally figured out what you meant with Time.deltaTime

    If anyone is interested, you have to do something like this
    Code (CSharp):
    1. Vector3 GetSwipeMovement(Touch touch)
    2.     {
    3.         if (touch.deltaPosition.magnitude != 0.0f && touch.deltaTime != 0.0f)
    4.             return GetPointOnPlane(touch.position) - GetPointOnPlane(touch.position + (touch.deltaPosition / (touch.deltaTime / Time.deltaTime)));
    5.         else return Vector3.zero;
    6.     }
    7.  
    8. public Vector3 GetPointOnPlane(Vector3 screenPoint)
    9.     {
    10.         Ray ray = mainCamera.ScreenPointToRay(screenPoint);
    11.         Plane hPlane = new Plane(Vector.up, new Vector3(1, 0, 1));
    12.         float distance = 0;
    13.         if (hPlane.Raycast(ray, out distance))
    14.         {
    15.             return ray.GetPoint(distance);
    16.         }
    17.         else return GetPointOnPlane(screenPoint);
    18.     }