Forum rules - please read before posting.

Player Movement Parallax

I'm working on a 2D game with direct movement. I'm adding some parallax layers using the Parallax2D script.

Where it gets tricky is that I'm also adding some fake 3D floors as well. I'm achieving this by using the Image Warp plugin that basically skews the top edge of my 2D floor as the camera moves. It looks great except for the character, which now slips quite a bit like he's moonwalking.

I know I can compensate for this based on the camera movement (comparing the last frame's position to the new frame) and also accounting for the sorting map scaling. The problem is, when I directly adjust the position of the character using transform.position, even by a tiny bit, it dramatically affects the character's movement.

So my question is, how can I adjust the character's position each frame without messing up Adventure Creator's character movement? I'll need it to work for both the player and NPCs.

Comments

  • edited July 2020

    Overriding the character's root position will cause problems, but you should be able to adjust the sprite child's local position without much fuss. You can access this with:

    myCharacter.spriteChild.localPosition;
    
  • I thought about that, but then the vicinity hotspot detection would be off, among other things.

    Figured out a solution (for anyone searching in the future):

    When the player movement is zero (transform.position is the same between frames), you can manipulate the position manually without messing up Adventure Creator.

    So then it was a matter of adjusting the speed of walking. In the Char.cs file, I just added a "parallax factor" multiplier when the sortingMapScale gets set in the UpdateScale() function. My parallax factor is adjusted based on the scaling of the sorting map. Then I added a compensation variable that can be set in the editor in case it doesn't match up to the sorting map scaling due to artwork.

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.