Changing position with lerp on multiple layers problem

Show us your works in progress and request feedback

Post » Sat Jun 03, 2017 3:47 pm

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 :D

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 :(

___

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

- https://www.dropbox.com/s/jrvcwiplmx1vo ... 9.c3p?dl=1

- 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
Chris Hinz

Design, visual development and illustration

www.hinz-art.com
B
7
S
1
Posts: 50
Reputation: 542

Post » Sat Jun 03, 2017 4:58 pm

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

Design, visual development and illustration

www.hinz-art.com
B
7
S
1
Posts: 50
Reputation: 542

Post » Sat Jun 03, 2017 6:27 pm

Hey bud, you have the wrong forum for your question :)
B
9
S
1
Posts: 24
Reputation: 513

Post » Sat Jun 03, 2017 8:04 pm

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.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sat Jun 03, 2017 9:18 pm

@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? :P Or must it be moved by moderators)

@99Instances2Go

Dear friend! :D 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 :D

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 :D (always feel a bit embarrassed to show such early work in progress things. So maybe you'll enjoy LEAVE, my last Construct project www.hinz-art.com/LEAVE

Best,
Chris
Chris Hinz

Design, visual development and illustration

www.hinz-art.com
B
7
S
1
Posts: 50
Reputation: 542

Post » Sun Jun 04, 2017 8:06 am

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 :D
- 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 :D
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
Chris Hinz

Design, visual development and illustration

www.hinz-art.com
B
7
S
1
Posts: 50
Reputation: 542

Post » Sun Jun 04, 2017 8:14 am

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 :D

I will keep you updated ;)
Chris Hinz

Design, visual development and illustration

www.hinz-art.com
B
7
S
1
Posts: 50
Reputation: 542

Post » Sun Jun 04, 2017 8:18 am

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.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sun Jun 04, 2017 2:16 pm

@99Instances2Go

LOOK AT THIS BEAUTY :D: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 :)))))

a bit odd how happy something like this makes me :D

Thanks again and again!

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

Design, visual development and illustration

www.hinz-art.com
B
7
S
1
Posts: 50
Reputation: 542


Return to Works in Progress/Feedback Requests

Who is online

Users browsing this forum: blackhornet, Moerk and 0 guests