Pin to object without rotation

1

Attached Files

The following files have been attached to this tutorial:

.capx

playerandmenurotating.capx

Download now 76.89 KB

Stats

4,437 visits, 6,778 views

Tools

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 12 Jul, 2013. Last updated 19 Feb, 2019

The Pin behavior works nicely in most cases, but there is a current situation where it can bring some problems. For example, if you want to have a menu display over the head of your player and follow the player, the menu will rotate according to the player rotation, even with a "position only" setting.

This mini-tutorial is here to help you use the pin behavior in those situations.

Problem

In this example, the player (black sprite) has a "rotate" behavior.

The 3 MenuIcons (blue sprites with 1 to 3 bars) are pined to the player, with a "position only" setting.

When the player rotates, the menuIcons rotates too, because their relative position to the player has to stay the same (this isn't a bug, it's the intended behavior). Though, in our case, that's not what we want.

Solution

We have to think of why the icons rotate around the player. They are all pined to a position above the player, and this position is moving, and so are the 3 icons. What we need is to pin the icons relatively to the player's origin, its center. As the pin don't let you choose an image point to pin to, we need to "simulate" a non-rotating image point.

Here comes the Hook sprite, a 1x1 invisible object, positioned and pined in the center of the player, with "position only" setting. This point will follow the player but never rotate, making it a perfect candidate for us to pin our Icons to.

Implementation

With those simple events, we create a "pin chain", and the final comportment is exactly what we needed. This simple trick can be used in numerous case, and is a lot simpler than repositioning every tick by hand the objects you couldn't pin before.

In the capx provided with this tutorial, I made the hook a little bigger that what I described and let it visible, to make it more understandable.

.CAPX

playerandmenurotating.capx

Download now 76.89 KB
  • 1 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • I'm playing around with these older Construct 2 features and coming across new features that supersede some of the older workarounds.

    In Construct 3 you can pin MenuIcon to the Player and use the new Bar Style ( not Position Only ) which keeps the MenuIcon pinned in a row above the rotating Player object without the need for the Hook workaround.