Keep an object attached to another

Get help using Construct 2

Post » Wed May 21, 2014 11:40 pm

Does the player's pin to the PlayerMovement apply after the weapon's manual move to the player? What's the order in which events and behaviors are acted on?
B
10
S
2
Posts: 104
Reputation: 1,140

Post » Wed Sep 03, 2014 10:06 am

I hate to do it but....
Bump.
Don't tell me you guys never tried to keep an object attached to another before?
B
6
S
2
Posts: 9
Reputation: 460

Post » Wed Sep 03, 2014 10:36 am

@tublood, ofcourse we have and we have never had many issues with it..

If you could share your capx or at least your events we might see where things go faulty..

The two most common mistakes are:
- pinning every tick instead of once with a triggered event..
- setting the position of object1 to a position relative to object2 before chanching the position of object2 in the same tick

if these don't apply helping without having a look at your events is almost impossible..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Sep 04, 2014 6:24 am

Message: tublood can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
Thanks for your advice
And here is the video
http://youtu.be/N44vn5ZZIdE
Object 1: Red square called HitDetect.
Object 2: Black rectangle called PlayerBound, at the very back of the character, using platform behavior
Object 1 set to Player Sprite's hitbox1 image point ( current at the origin )
Player Sprite pinned to PlayerBound ( position and angle ) at the start of the layout ( 1 time pin only )
Object 1 lags behind while object 2 is moving ( u can see in the video )

In the Code i set
Every tick
--------- Hitdetect set position to PlayerSprite ( image point "hitbox1" )
B
6
S
2
Posts: 9
Reputation: 460

Post » Sat Jan 31, 2015 7:43 pm

I'm having the same issue. :l
B
8
S
2
Posts: 6
Reputation: 518

Post » Fri Mar 04, 2016 6:42 am

Been working on a similar issue this evening, and after lots of research (as you may also have already figured out) the issue comes from setting position of a sprite (or worse, pinning) to another sprite WHICH ALSO has its position set to an object. For instance, an invisible, rectangular controller sprite handles collision and movement. To this, we set the position of the visible player sprite (containing the animations). For accuracy, we set image points to the visible player sprite (as the invisible collision sprite is often smaller, and will not have a visual guide for where to set the image points). Then, we set the second sprite (sword, gun, shield, shadow, etc.) to the visible sprite's image point, and therein lies the problem. We have "pinned" (through events, not behavior) s sprite to a sprite to a sprite, and C2 HATES that.

To test this, create a platform with a sine behavior. Set its movement to either horizontal or vertical. My platform is small, 64x16, so I'll set the period to 3 and magnitude to 32. Size yours as you wish, and use appropriate settings. Now create a rectangle sprite with platform behavior, and place it on the platform. This will be our "Controller", a rectangular collision detector, as is best practice for platforming. Next, we create our hero sprite, a visible, but non-solid representation of the player controlled hero. For this test, it can be a larger rectangle, or add your favorite animated asset. We'll name this sprite "Player". Every tick, set the position of "Hero" to "Controller". (I know this is all platformed 101, bear with me). Now, lets set a new image point on "Hero". Right-click and quick assign it to "right" (unless you're feeling ambitious and used an animated asset, in which case feel free to assign the point to wherever the hand appears). This image point will be where we hold our "object" sprite. I'll name my point "Hand" and my new sprite object "coffee". You can name yours whatever is appropriate. Now I'll create the sprite, "Coffee" and set it's position every tick to "Hero" image point 1 (remember, it's 0 based, and 0 is the origin, so your new point is 1. You can also set the "Coffee" sprite to "Hero" at image point "Hand" if you prefer names over numbers, but don't forget the quotes.)
Alright, lets test it out. Assuming I wasn't sleepy enough to forget a step, you ought to see the "Controller" and "Hero" sprites moving together perfectly, but notice that "Coffee" is always a bit behind, sort of like a LERP effect. This is the lag caused from setting the position of one sprite to a second sprite which is positioned to a third.

Now, try setting the position of "Coffee" to a similarly placed "Hand" image point on our original "Controller" sprite. Magically, they all move in sync now.

This is a bit of a pain, since you lose the visual reference of the "Hero Sprite", and since the origin point and size of your controller and hero are rarely the same, a lot of tweaking comes into play when fine tuning the position of your held object for every animation frame. I'm sure you could find the position of each point on the "Hero", then offset that by the difference in origin points between the "Hero" and "Controller", but again, lots of extra work.

If anyone has any ideas for a non-plugin fix, or method of determining image points without your visual reference, I would love to hear! Or if I've just plum lost everybody, I'll try to clarify. I do hope this has been helpful, and I hope some one comes up with better solutions!

TLDR: Use one sprite to set position of all other sprites, do not set position to a sprite which has its position set to another sprite. A headache, but works.

Apologies for reviving an old topic, but it seems to be unsolved. Also for any errors, it's very late.
B
17
S
7
Posts: 21
Reputation: 1,711

Post » Thu Jun 16, 2016 3:34 am

Wow. You just solved a problem that's been stumping me for 2 years. Thank you so very, VERY much.

It was a bit of a hassle to copy all of the relevant animations with their moving "hand" image points from the player to the movement object, but with that done it works perfectly.

Seriously, thanks a lot.
B
10
S
2
Posts: 104
Reputation: 1,140

Previous

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 23 guests