How to get the real angle of objects a la LayerToCanvas?

0 favourites
  • 5 posts
From the Asset Store
Scrollbars with FULL functionality and versatility, just like the ones you can find in AAA games!
  • Hello Scirra Community,

    is there a way to detect an objects real angle?

    Example:

    Layer 1 = Sprite 1

    Layer 2 = Sprite 2

    • Sprite 2 is set to Sprite 1 + offset (to mimic a shadow)
    • if Layer 2 gets rotated, Layer 1 naturally doesn't
    • therefore setting Sprite 2s angle to Sprite 1s wont work anymore.

    I came around this problem with positions using the fantastic function of LayerToCanvas and CanvasToLayer.

    Is there something similar or a workaround to detect the "true angle" in relation to the canvas?

    Thanks for any advice and help

    Best,

    Chris

  • EDIT:

    Or is there a way to show/render/blend/view Sprites only on certain objects (on different layers) this would make creating custom shadows so easy!

  • EDIT:

    Ok, one night of thinking brought me to the following:

    It would be really useful to have an easier way in C3 to detect the true position of an object and its true angle (with true I mean on canvas, incase separate layers are rotated for example).

    Using the CanvasToLayer method works, but it only gives the "true" position of an object for one different layer. So if you need to translate multiple objects to multiple layers it can get quiet confusing.

    And there seems to be no direct way to detect an objects true angle (on canvas).

    Regarding the whole true angle issue, I figured it might be a possibility to "pin" an object (for example) behind or in front of the player object, detect the players position X,Y through CanvasToLayer and detect the pined objects position X,Y through CanvasToLayer and set a third objects width to X=PlayerX,Y and Y=PinedObjectX,Y and its angle to ..... mmh wait. But you get the point: the goal is to translate the true angle of the player object to a different layer by detecting two points "on" the player object, so a third object can mimic those two points, creating the true angle on a different layer.

    Does anybody know how I can set the "third object" so it uses the two CanvasToLayer coordinates to create the true angle of the PlayerObject?

    I'm thankful for any help

    Best,

    Chris

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Here we go <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    https://www.dropbox.com/s/ruzmghista1pn ... e.c3p?dl=1

    This is the solution mentioned in my post above. It works. But it has a tiny delay <img src="{SMILIES_PATH}/icon_e_sad.gif" alt=":(" title="Sad">

    Any optimisation tipps?

    Explanation:

    • Left, right arrow rotates the player
    • Up and back arrow accelerates
    • Press E and R to rotate the level ... and see how the custom shadow repositions itself according to the levels rotation and the new true angle (rotation will be done automatically later) - E is a lot faster for testing purposes

    My goal is:

    • To set the "Custom Shadow" to the players true rotation (level gets rotated, player doesn't, the shadow should still rotate) ...
    • ... so I can place the shadow on a different layer since I want to set its blend mode to "source in" and place all "ground" elements on the same layer to have the shadow only be visible on the ground objects but not the rest.
  • SOLVED:

    It actually worked:

    http://www.hinz-art.com/testserver/Cassini_2/index.html

    https://www.dropbox.com/s/jscin0tpb5tg2 ... d.c3p?dl=1

    Project file is structured, labeled and commented.

    I hope this will help anyone who is trying to find a way to get the "true angle" of objects cross different layers (with different rotations)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)