Author Topic: How to make character control speed consistent across multiple resolutions?  (Read 2415 times)

anachronic designs

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Hi, I'm using NGUI to make a top down action game and am running into a problem with my character control. I am using transform.translate to move the character, but the character moves faster at higher resolutions (the speed is not consistent across different resolutions).

I understand from reading old posts that translate() can give unexpected results due to how NGUI scales the view, but have not been able to figure out how to solve the problem other than changing the speed variable depending on the resolution, which seems cumbersome  :-\. Any tips on an easier way to make translate() work the same across multiple resolutions? Thanks!!!

Here is the code I'm using to move my character. I am using InControl, so inputDevice.Direction.y (or x) returns a value between -1 and 1. Please let me know if there is any more info that would be helpful.

  1. // move up
  2. transform.Translate ( Vector3.up * speed * Time.deltaTime * inputDevice.Direction.y , Space.World );
  3. // move down
  4. transform.Translate ( Vector3.right * speed * Time.deltaTime * inputDevice.Direction.x , Space.World );
  5.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
This doesn't seem like an NGUI question, and I am not familiar with transform.Translate. I just modify transform's localPosition when I need to move it.

anachronic designs

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Ok well, thanks anyway then eh. This is my first time trying to make a pixel perfect output (where you just see more of the gameworld at a larger resolution instead of scaling the graphics, so maybe the problem would still be happening if I wasn't using NGUI...

For anybody else having a similar issue, I've tried using AddForce and setting RigidBody2D velocity directly but the problem persists. Switching to setting velocity directly did get rid of an annoying bounciness issue with the 2D physics and transform.translate() though :)