Problems with objects following the player

Get help using Construct 2

Post » Fri Dec 28, 2012 7:45 pm

Hi everyone! Sorry to bother, but I need help!

Well, my intention is to develop a game where your character must collect eggs scattered at the stage and take them to a checkpoint. When you pick up one egg (by touching it), it follows you. Get another one and it will also follow you, right after the last egg you caught, making a line.

The problem is: After getting the second egg, the first one stops following you properly, staying fixed at one point, instead of going to the correct Player fixed point (It looks like the lerp formula is being ignored somehow).

I don't know what to do to fix it. Could you guys give me a hand?

This is my code so far:



And a link to play the demo:

http://dl.dropbox.com/u/12937330/follow_test/index.html

Thanks in advance!
B
12
S
6
G
3
Posts: 100
Reputation: 3,836

Post » Fri Dec 28, 2012 10:01 pm

Event 5. You check if eggsSaved=1, only then should the first egg follow the player. This is probably not what you want.

Also, you are not doing this very efficiently. Everything you have done could be done with one object with a few instance variables. that way you won't have to repeat code. 99% of the time if you are repeating code there is a better way.

Let me know if it doesn't work for you.
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Sat Dec 29, 2012 12:33 am

[QUOTE=sqiddster] Event 5. You check if eggsSaved=1, only then should the first egg follow the player. This is probably not what you want.

Also, you are not doing this very efficiently. Everything you have done could be done with one object with a few instance variables. that way you won't have to repeat code. 99% of the time if you are repeating code there is a better way.

Let me know if it doesn't work for you.[/QUOTE]


I thought that I had to check it in order to make the first egg properly follow the player. I would never guess it was that.

I know it's not the best way to do this. Before this I tried to create the catching system only using one egg object, but I couldn't figure how to treat each object instance separately, so I made this way in order to produce some result before I go crazy :P. If you have any suggestions on how to do this I'd really like to learn!

Thank you very much for your help!!pcfernandesjr2012-12-29 00:37:31
B
12
S
6
G
3
Posts: 100
Reputation: 3,836

Post » Sun Dec 30, 2012 6:18 pm

OK, I made some changes at the code, now using only two objects: One to be caught, then it is destroyed to be replaced by other who will follow the player.



It is working well. But there's still a problem. the second egg caught doesn't follow behind the first egg, but follows the player, hiding itself behind the first egg.

I'd like to know if there's a way to create events that affects a specific instance, since every change I want to make at the variables affects the object, not an specific instance.

Thanks for the help!pcfernandesjr2012-12-30 18:18:56
B
12
S
6
G
3
Posts: 100
Reputation: 3,836


Return to How do I....?

Who is online

Users browsing this forum: blackhornet, jeffige, TheHat, Yahoo [Bot] and 1 guest