Forum rules - please read before posting.

2D mode diagonal movement speed

edited August 2015 in Technical Q&A

I wanted to share the result of something I've been fiddling with for how the 2D walk vector magnitude is calculated in the Char.cs script.

The existing calculation works just fine for vectors that are almost entirely vertical or horizontal, but seemed to be giving unexpected results for diagonals. Characters would look like they were moving back and forth in perspective much faster than they should - which became particularly noticeable with scenes that had low values for their Vertical Movement Factor and a large difference between the smallest and largest scale on their sorting map.

The conclusion I reached was a need to bias the drop off of the reduction in the movement vector's magnitude so that it would return values closer to 'normal' speed only once the vector was much closer to horizontal.

At present I'm magnifying the Sine angle result ("upAmount" in the current code) by setting it to the power of the scene's vertical reduction factor and using that as the proportion of magnitude to remove from the original newVel vector.

Something like:

M = 1 - ( sin(A)^f ) * ( 1 - f )

How I'm applying it as a modification:
float verticalReductionFactor = KickStarter.sceneSettings.GetVerticalReductionFactor();
float reduction =  Mathf.Pow(upAmountverticalReductionFactor) * (1f - verticalReductionFactor);
float mag = 1f - reduction;
newVel *= mag;


By no means is this a final and correct solution - Maybe someone more mathematically able could suggest a function that would replicate perspective more accurately? (I was wondering about some combination of the inverse square law and a scene specific variable that represents the distance of the camera to the stage?). For now though, this appeared to be giving slightly more appropriate movement speeds on diagonals in my tests.

Has anyone else been looking at this? Or have I missed a setting somewhere which renders this not a problem normally?

Comments

  • I don't have an answer off the top of my head, but I'll take a look at this myself for a future release.
  • My own testing finds that changing this generally makes the effect worse.  If you find results that work well for you, please post them here along with the kind of sortingmap scale / reduction factor values you're using, and I'll revisit this.
  • Thanks for taking an initial look anyway Chris. I haven't improved on my original attempt yet, but if I do I'll certainly share the findings :)
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.