Changing position with lerp on multiple layers problem

0 favourites
  • 9 posts
From the Asset Store
Simplistic hyper-casual game with nature elements. Tap to switch between the 4 elements and reach a better score.
  • Hello C'ers,

    (Im so far enjoying C3 a lot!!! Working on R34 at the moment)

    Im looking for feedback on a bug I just can't get rid of. Driving me nuts <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy">

    Im trying to make Sprites with a bullet behaviour

    "collectable" --> on input + overlapping players grab zone = set position of the collectable to "Lerp(Self,Player,X)" and so on.

    Everything starts to work just fine but sometimes the collectables just bounce of the grab zone. I guess it has something to to with the rotated layer underneath (?) (collectables and the whole level is rotating, player is on a different layer and not affected by the rotation).

    The pathfinder also didn't do the job <img src="{SMILIES_PATH}/icon_e_sad.gif" alt=":(" title="Sad">

    ___

    If anybody wants to have a look, those are the steps to recreate the problem:

    • press R or T to rotate the level
    • wait for yellow circles
    • keep U pressed (to collect collectables within reach)
    • now many of them bounce of strangely

    Sorry for the messy structure of the file (its the MVP/prototype/"trying out things file"). But its not big yet.

    Any help is greatly appreciated!

    Whoever just wants to have a quick glimpse at it before downloading the construct3 file:

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

    Best,

    Chris

  • EDIT: There is something wrong with the Z key / slowing down time feature. I haven't checked on this yet

  • Hey bud, you have the wrong forum for your question

  • I not gonna fix this in your project. It is to complicated for me, and i see things that i dont understand.

    Like that 'for every zero seconds' every where in the events. Like all those duplicate key triggers.

    But i gonna do my best to explain what is happening. So you can fix it yourself.

    You have an object on a rotated/parallaxed layer, and you want to move it towards a position on another and different rotated/parallaxed layer. In your case different means not rotated/parallaxed at all for the second layer.

    Lets explore this.

    https://www.dropbox.com/s/hd03y47rwdzp4 ... 1.c3p?dl=0

    In this .c3p i present you 2 layers. On each layer you find a sprite representing a coordinate system. A coordinate system is just and no more then a way to describe where a certain point is. That point is so much units on the X axes and so many units on the Y axes.

    On each layer you also see a sprite on 6 units on the X axes and - 6 units on the Y axes. That sprite is named 'marker'.

    Now press U on the keyboard to rotate layer 0. You see that the non of the markers is changing position towards there coordinate system. Both still sit on 6 units on the X axes and - 6 units on the Y axes. Yet they are not on the same position on the screen.

    The Coordinate System for layer 0 changed. (well it rotated). So now both markers live in a different world. You can not longer say that the marker on layer 1 sits on 6 units on the X axes and - 6 units on the Y axes in the the coordinate System for layer 0.

    Next c3p.

    https://www.dropbox.com/s/bql5dufygbphj ... 2.c3p?dl=0

    Now i added two sprites named 'PlaceOnLayer' plus a number to represent on what layer that they are.

    And both layers are rotated.

    Now clearly if we set 'PlaceOnLayer0' (that object is on layer 0) to the position of 'markerOnLayer1' (that object is on layer 1), IT ENDS UP on the position where 'markerOnLayer0' sits.

    That is because if you position something on layer 0, the position is calculated with the coordinate system on layer 0.

    So we have to invoke terrible math to translate coordinates (X&Y) from the coordinate system in layer 0 to the coordinate system in layer 1.

    Luckily c3 (and 2) has Math Expressions that do all the work for you. Those expression are

    LayerToCanvasX & LayerToCanvasY

    and

    CanvasToLayerX & CanvasToLayerY

    https://www.dropbox.com/s/7267s27vargan ... 3.c3p?dl=0

    We can not straight translate from a coordinate system on layer 0 to that on layer 1.

    We have to do it in 2 steps.

    First we use LayerToCanvasX & LayerToCanvasY. Those expressions translate an X/Y coordinate on a certain layer to the coordinate system of the screen (Canvas).

    The screen is never ever rotated/parallaxed, so it has always a default and known coordinate system. We just use it to temporally push our rotated/parallaxed X/Y in a known steady world.

    Secondly.

    We use CanvasToLayerX & CanvasToLayerY to fly those coordinates from the that steady world coordinate system to the coordinate system on the other layer.

    So its.

    Step 1 .. use LayerToCanvasX to translate a X on a rotated layer to a non rotated world.

    Step 2 .. use CanvasToLayerX to translate the X on the non rotated world to another layer.

    In the previous .c3p you see this happening using 4 local variables.

    But it can also be done all at once in 1 action:

    https://www.dropbox.com/s/4c9r3fjk87g5k ... 4.c3p?dl=0

    Hope my English was good enough to explain this. Sorry if not the case.

  • abj84 Sorry mate, which one would be more appropriate? I mean its not a bug, so I thought this was fitting. Will gladly move it to another topic (can i move things? Or must it be moved by moderators)

    99Instances2Go

    Dear friend! oh man where do I start. I've never expected such a precise, helpful, friendly and well written answer with so many perfect examples. I've seen many friendly replies in this forum but you are the cherry on top!

    I hope I will be able to execute your advice - but think: if Im not, I am probably just stupid

    Thanks again! Have a great day. Thank you

    Just wanna show you that I have more Construct skills then compiling unstructured commands in a colourful capx

    Best,

    Chris

  • Good morning 99Instances2Go,

    I was experimenting last night and this morning and came to the following:

    • I didn't try your attempt yet (because actually I'm afraid it wont work). Let me explain:
    • What you said and your solution seems perfectly fine and will probably work for detecting the "real" coordinates over multiple layers with different parallax
    • But doesn't this mean it should work with object on the same layer (in the same coordinate system)
    • So to try if your "right" way will work I thought about this:

    1. attempt: On event - move collectable to same layer as the player + set position to perp(self,player,x)

    https://www.dropbox.com/s/lqse3r6v6210g ... 5.png?dl=1

    • But it seem (when rotated) to still stay in its "own" coordinate system. So i tried this:

    2. attempt: (You can skip this one actually since I changed this version in attempt Nr. 3)

    • Created a new object (which will be the collectable in its active state) /like a different coloured clone
    • Gave it an instance variable (0)
    • On (collecting) event: set instance variable to 1
    • If instance variable = 1 set "clone's" position to perp(self,player,X)

    + trigger once while true: Old collectable - Spawn - "clone" on "Player's" layer

    • destroy "old collectable"

    https://www.dropbox.com/s/5dxow7en6mfi8 ... 7.png?dl=1

    Also didn't work.

    3. attempt:

    • This is a modification of the 2. attempt
    • I found out, that my instance variable on the "cloned" collectable on the players layer didn't work <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy">
    • So I tried the same approach with a global variable
    • Since then the new (cloned) collectables at least lerp to the player position successfully and don't bounce of the grab zone anymore
    • But they still start lerping from the "wrong/old sprite's layer coordinate"

    https://www.dropbox.com/s/lgrm657d372ag ... 8.png?dl=1

    Before trying your attempt I was just wondering if you think that it will do any difference if it already doesn't work even if the sprites are on the same layer. The point is: I don't understand why to objects can't be lerped to each other when on the same layer just because there is a rotating layer underneath. Confuses me <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy">

    Thank you so much for all your help!

    New capx

    https://www.dropbox.com/s/4st58c0i4urcx ... 9.c3p?dl=1

    Have a great day,

    Chris

  • EDIT!!!

    Aahhhhhhhhhh. I see: The third attempt is working. But if the "new sprites" spawn at the "old sprites" location (even if it is on the player's layer), they will still spawn at the old sprites "location" in the old coordinate system. And therefore work but start of at the wrong place (old sprites location)

    So your way should indeed work!

    To me it seemed the same. But now I see its not

    I will keep you updated

  • They are not on the same layer. The player and its collection area are on a different layer then the dots.

    The layer with the dots is rotated, the layer with the player is not rotated.

    Not saying that it is your only problem. Test your original project as follow. Rotate the layout, in stead of 1 layer. Just to test. Did it solve the problem, then it is the only problem. Did that test did not solve the problem, that there is something else also acting up.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 99Instances2Go

    LOOK AT THIS BEAUTY <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy">:D:D:D:D

    https://www.dropbox.com/s/lz6ru0uhvcg93 ... 3.c3p?dl=1

    oh man, I must say it took me a couple of good hours of frustration. But finally I managed to understand and execute your advice.

    Anybody who wants to try it:

    • Press U to lerp the circle to the player
    • Restart Layout
    • Press R to rotate the "rotating layer"
    • Press U now AAAAND THE CIRCLE STILL lerps to the player <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">))))

    a bit odd how happy something like this makes me <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy">

    Thanks again and again!

    #solved (lerping position of two objects on different layers when rotated)

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