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

Get help using Construct 3!

Post » Mon Jun 12, 2017 5:36 pm

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

Design, visual development and illustration

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

Post » Mon Jun 12, 2017 7:42 pm

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

Design, visual development and illustration

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

Post » Tue Jun 13, 2017 8:34 am

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

Design, visual development and illustration

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

Post » Tue Jun 13, 2017 9:22 am

Here we go :)

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 :(
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.
Chris Hinz

Design, visual development and illustration

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

Post » Tue Jun 13, 2017 8:38 pm

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

Design, visual development and illustration

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


Return to How do I...?

Who is online

Users browsing this forum: No registered users and 0 guests