Pin to Image Point?

Get help using Construct 2

Post » Wed Nov 21, 2012 8:46 pm

[QUOTE=inkBot] [QUOTE=sman118] @aruche that is AWESOME and exactly what I needed. Problem is that I'm trying to set the object down and any code I try to figure out isn't working. I'm trying to toggle the carrying off and have it end up at the player's image point and left there on the stage.[/QUOTE]
If you're doing what I think you're doing, you have similar setups for the events for turning carrying on and off. Problem with this is that they will toggle in order.

This order of events:

+ Player presses S
+ Carrying = false
- Toggle Carrying

+ Player presses S
+ Carrying = true
- Toggle Carrying

It's first going to toggle the Carrying variable, but instantly afterwards it's going to toggle it again, because the conditions for that event have now become true. This will give the appearance that it doesn't work and you can't pick up the item, while in reality you're picking it up and immediately putting it down. If you reverse the order you'll have the opposite problem, you can pick the item up, but you can't put it down.



[QUOTE=sman118]I really appreciate the help. Also, if you could friefly explain what you did, that would help me learn it for next time. Thanks![/QUOTE] He's effectively doing what I wrote in my post.[/QUOTE]

So are you saying that there's no way of setting the object back down? Maybe I should look into destroying the object and spawning a duplicate where I want it set down. It might even be easier to attach a sprite object containing all of the objects you would carry to the player. That way I could just give the illusion of holding it. Thoughts?
B
40
S
11
G
6
Posts: 228
Reputation: 6,946

Post » Thu Nov 22, 2012 1:52 am

[QUOTE=sman118]So are you saying that there's no way of setting the object back down? [/QUOTE]
Nope, just that getting it to work will need some finagling. This issue hasn't come up for me personally, so I haven't tried to solve it for myself. So currently I have no real solution to give.

[QUOTE=sman118]Maybe I should look into destroying the object and spawning a duplicate where I want it set down. It might even be easier to attach a sprite object containing all of the objects you would carry to the player. That way I could just give the illusion of holding it. Thoughts?
[/QUOTE]
It's certainly something you could do. However, it would have the same problem as before, just replacing carrying/putting down with destroying/creating. The problem lies with the keyboard object running every event in sequence.

There was a discussion not too long ago about a very similar subject, and I think Ramones had a solution to the issue. http://www.scirra.com/forum/using-one-button-and-variable-to-switch-states_topic58648.html?KW=
Not sure if that capx is still available though.
B
73
S
20
G
10
Posts: 524
Reputation: 9,896

Post » Thu Nov 22, 2012 2:59 am

Couldnt open your capx ...using r109

Anyway, try the following capx-

download

Good luck
B
19
S
6
G
7
Posts: 1,205
Reputation: 7,298

Post » Thu Nov 22, 2012 4:09 am

Figured it out! At least I think I did. So I went and followed the steps that @chrisbrobs used to pin the object to the player at the image point. Problem is, it wouldn't follow the image point as it updated through the animations.

So to fix that, I created a sprite (that will be invisible during play) that would update its position every tick to be at that specific image point that I wanted. Then, instead of pinning the object to the player, I pin it to the sprite that is updating to be on the image point. I still have to do more testing, but so far its working great.

Thanks for everyone's help!
B
40
S
11
G
6
Posts: 228
Reputation: 6,946

Post » Thu Nov 22, 2012 6:03 am

Here's my take at it:
prr-PinTest-01.capx

As far as I remember using state conditionals as sub-events of a press button used to evaluate just one of the options for this kind of situation, but for some reason it doesn't work that way anymore.

Something like:
+On S pressed
-+Var = 0 -> set var to 1

-+Var = 1 -> set var to 0

Am I mistaken or this behavior has changed along the way?Animmaniac2012-11-22 06:48:45
Scirra Employee
B
129
S
45
G
15
Posts: 705
Reputation: 15,413

Post » Thu Nov 22, 2012 6:10 am

@Animmaniac

It might use "else" to replace "condition: Var = 1".
B
97
S
22
G
177
Posts: 4,111
Reputation: 103,525

Post » Thu Nov 22, 2012 6:48 am

I think you are right, I was confusing it with the else trick.

I got intrigued by how to optimally solve it when the on and off conditions are not the perfect inverse of one another. For instance, just when picking the civilian it must be overlapping the player, but to release it not.

Something like:
+On S pressed
-+Var = off
-+is overlapping player -> set var to on

-+Var = on -> set var to off

In my example I couldn't solve it without complicating too much so I left both the on and off conditions depending on the overlapping just to make things simpler to understand, although it was not the ideal.

Any ideas of how to solve this beautifully?
Scirra Employee
B
129
S
45
G
15
Posts: 705
Reputation: 15,413

Post » Thu Nov 22, 2012 1:32 pm

@animmaniac That is really cool. I like how the Civilian box kind of shifts to the position. I really need to look into "lerp". It looks like it can be used for easing things into place which would give a more organic look to some of the things that I'm doing.

However, with the way I'm working, I need the lifted object to constantly be stuck to an exact spot on the animation. For instance, If I animate someone bending down and picking up a box, I need the box to stick to the character's hand the in each frame of animation.

That's why I went with creating an invisible sprite that updates to the image point through the entire game and then pinning to that sprite using @chrisbrobs method.

Here's the capx: http://dl.dropbox.com/u/56104169/PinTest%2011-21-12.capxsman1182012-11-22 13:33:21
B
40
S
11
G
6
Posts: 228
Reputation: 6,946

Post » Fri Nov 23, 2012 1:44 pm

I found a more elegant solution for triggering the events and updated my example:
prr-PinTest-01.capx

@sman118 If you want to stick it to the image point just remove the lerp. You don't need to create extra objects for it.

I don't know exactly how your game is supposed to work, but if your character can hold only one civilian at a time I recommend picking by storing the civilian UID like I did. This avoids possible annoying bugs that may appear as your project grows, since there's absolutely no way to pick more than one object this way.
Scirra Employee
B
129
S
45
G
15
Posts: 705
Reputation: 15,413

Post » Fri Nov 23, 2012 3:26 pm

@Animmaniac That works great. I'll have to study up on UID's as I'm still pretty new and that is a bit out of my wheelhouse.

The reason that sticking to those image points are so important is because I'm going to have situations where the animation and movement is going to change whether you are holding an object or a person.

If you're lifting an object, the animation will have them bending over, picking it up, and carrying it above their head. I need to be able to have the object follow an image point on the animation so it lines up.

More importantly, when you are carrying a civilian I am going to have a stock set of animation for the torso, legs, and cape. Then I'm going to use the image point to overlay the player's head, arms, and whichever person they are holding.

B
40
S
11
G
6
Posts: 228
Reputation: 6,946

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: bluemonkey, Khamsou and 24 guests