Forum rules - please read before posting.

2D Offset the player and have it partly walk outside the scene

Hi guys!
I am trying to achieve this effect on the below images. I need to offset the player so when close to the camera we get the effect that the player walks partly outside the scene. And when furthest back in the scene we want no offset I guess.

Anyone got any tips on how to achieve that?

image

image

Comments

  • How are you moving the player?

    If it's with Direct control, or a Character: Move to point Action, then the player isn't confined to the camera.

    If you're using point-and-click movement, I suppose it may be easiest to just offset the player's sprite child position - which is normally supposed to be at the same point as the root object, giving it a local position of (0,0,0).

    To achieve this, you could just attach a simple script to the sprite child that updates its position based on the y-position of its root, i.e.:

    using UnityEngine;
    
    public class OffsetSpriteWithY : MonoBehaviour
    {
    
        public float topY;
        public float scale;
    
        private void LateUpdate ()
        {
            float rootY = transform.root.position.y;
    
            if (rootY < topY)
            {
                float offset = (rootY - topY) * scale;
                transform.localPosition = Vector3 (0f, offset, 0f);
            }
        }
    
    }
    
  • Yes sorry! Should have added that - movement is controlled with point and click in this scenario. Thanks that script should to the trick!

  • Yay it works. Thanks! :smiley:

    image

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.