adding a player to follow the other player

Get help using Construct 2

Post » Tue May 06, 2014 1:17 pm

https://www.dropbox.com/s/kg3z2174yrr9d ... pe%29.capx

so, i have a few bugs and i cant seem to fix them, i want to have 2 players, when im using one the other follows, and so on, whats happening is i can only use one player, and when i switch to the other one it begins to follow the one im not using... i know the events are wrong but dont know what to do to fix them.. please help
B
5
S
1
Posts: 77
Reputation: 754

Post » Tue May 06, 2014 3:58 pm

I am looking at it now. When I get done going over it, I will try to post an updated version with it working for you. That being said, I noticed 1 thing that will probably help you get a little further. You are disabling the platform input on the deselected character, but you are trying to use the simulate platform button pressed to move it. If the input is disabled, you cannot use the input to move it. That is why the monster is not following when the human is active.
B
38
S
12
G
11
Posts: 331
Reputation: 7,712

Post » Tue May 06, 2014 4:24 pm

FragFather wrote:I am looking at it now. When I get done going over it, I will try to post an updated version with it working for you. That being said, I noticed 1 thing that will probably help you get a little further. You are disabling the platform input on the deselected character, but you are trying to use the simulate platform button pressed to move it. If the input is disabled, you cannot use the input to move it. That is why the monster is not following when the human is active.



yes i noticed im disabling it so its normal that it doesnt move, but i just dont know what else to do, so i left it like that.. hope you can help me :)
B
5
S
1
Posts: 77
Reputation: 754

Post » Tue May 06, 2014 4:55 pm

@kionysan
Ok, I have cleaned up your events and have it doing what (I think) you want it to do. I also duplicated your monster follow events to make some equivalent human follow events. This may not be what you want, it is just to show you the setup works both ways. You can find the capx attached.

A couple notes:
I noticed you had a couple every tick events as sub events. An every tick event which has any other conditions is redundant. Read this page to get more information:
https://www.scirra.com/blog/141/common- ... nd-gotchas

I also noticed, your events to change which player is selected were set up in a way that they were firing every tick. With small project, you wouldn't notice, but as your project grew in complexity, it could really bog it down. I added an event at the start of layout to disable input on the monster and moved all of the events to switch which is controlled as sub-events to the space bar event. That ensures they only fire when you want to change users, not every tick.

I noticed a scroll to event at the end which, because of your camera seemed redundant. I am not sure why it was there. If there is a reason I don't know about, you will want to add it back in.

I gave the camera the ability to follow the monster when it is the selected character.

Finally, because you were using the lerp function to move the camera, I figured the easiest method to move the follower would be to use the same method. I figure if you know enough about it to use it, what I did should make sense to you.

As a bonus, I decided to help you cut down the number of events by 1 more. Where you set the selected value, you were adding 1 to the value. Then, in a separate event, you were checking to see if the value was above 2. If it was you were setting it to 1. This method works perfectly and is a good way to make this kind of change but eats up another event unnecessarily. So, I threw in a function you can use in your future projects. The method is "whichcharacter = 2 ? 1 : 2". This is a very simple if/then statement and can be used any time you have 2 possible results. This is what it means:

whichcharacter = 2 -> If whichcharacter is equal to 2
? 1 -> Then return 1
: 2 -> If not, return 2

Because I wrote the function in the action to set whichcharacter, the result is, whichcharacter is set to the return value. So, if whichcharacter is currently 2, whichcharacter is set to 1. If not, it is set to 2.

Well, that was a long one but I hope it helps. Good luck with your project.
You do not have the required permissions to view the files attached to this post.
B
38
S
12
G
11
Posts: 331
Reputation: 7,712

Post » Tue May 06, 2014 5:20 pm

FragFather wrote:@kionysan
Ok, I have cleaned up your events and have it doing what (I think) you want it to do. I also duplicated your monster follow events to make some equivalent human follow events. This may not be what you want, it is just to show you the setup works both ways. You can find the capx attached.

A couple notes:
I noticed you had a couple every tick events as sub events. An every tick event which has any other conditions is redundant. Read this page to get more information:
https://www.scirra.com/blog/141/common- ... nd-gotchas

I also noticed, your events to change which player is selected were set up in a way that they were firing every tick. With small project, you wouldn't notice, but as your project grew in complexity, it could really bog it down. I added an event at the start of layout to disable input on the monster and moved all of the events to switch which is controlled as sub-events to the space bar event. That ensures they only fire when you want to change users, not every tick.

I noticed a scroll to event at the end which, because of your camera seemed redundant. I am not sure why it was there. If there is a reason I don't know about, you will want to add it back in.

I gave the camera the ability to follow the monster when it is the selected character.

Finally, because you were using the lerp function to move the camera, I figured the easiest method to move the follower would be to use the same method. I figure if you know enough about it to use it, what I did should make sense to you.

As a bonus, I decided to help you cut down the number of events by 1 more. Where you set the selected value, you were adding 1 to the value. Then, in a separate event, you were checking to see if the value was above 2. If it was you were setting it to 1. This method works perfectly and is a good way to make this kind of change but eats up another event unnecessarily. So, I threw in a function you can use in your future projects. The method is "whichcharacter = 2 ? 1 : 2". This is a very simple if/then statement and can be used any time you have 2 possible results. This is what it means:

whichcharacter = 2 -> If whichcharacter is equal to 2
? 1 -> Then return 1
: 2 -> If not, return 2

Because I wrote the function in the action to set whichcharacter, the result is, whichcharacter is set to the return value. So, if whichcharacter is currently 2, whichcharacter is set to 1. If not, it is set to 2.

Well, that was a long one but I hope it helps. Good luck with your project.



are you god? thanks a lot, it is so much better and easy now, i learned a lot from what you did just now, you have my thanks.sorry for any trouble you went to make this masterpiece. :DD
B
5
S
1
Posts: 77
Reputation: 754

Post » Tue May 06, 2014 5:28 pm

kionysan wrote:
FragFather wrote:@kionysan
Ok, I have cleaned up your events and have it doing what (I think) you want it to do. I also duplicated your monster follow events to make some equivalent human follow events. This may not be what you want, it is just to show you the setup works both ways. You can find the capx attached.

A couple notes:
I noticed you had a couple every tick events as sub events. An every tick event which has any other conditions is redundant. Read this page to get more information:
https://www.scirra.com/blog/141/common- ... nd-gotchas

I also noticed, your events to change which player is selected were set up in a way that they were firing every tick. With small project, you wouldn't notice, but as your project grew in complexity, it could really bog it down. I added an event at the start of layout to disable input on the monster and moved all of the events to switch which is controlled as sub-events to the space bar event. That ensures they only fire when you want to change users, not every tick.

I noticed a scroll to event at the end which, because of your camera seemed redundant. I am not sure why it was there. If there is a reason I don't know about, you will want to add it back in.

I gave the camera the ability to follow the monster when it is the selected character.

Finally, because you were using the lerp function to move the camera, I figured the easiest method to move the follower would be to use the same method. I figure if you know enough about it to use it, what I did should make sense to you.

As a bonus, I decided to help you cut down the number of events by 1 more. Where you set the selected value, you were adding 1 to the value. Then, in a separate event, you were checking to see if the value was above 2. If it was you were setting it to 1. This method works perfectly and is a good way to make this kind of change but eats up another event unnecessarily. So, I threw in a function you can use in your future projects. The method is "whichcharacter = 2 ? 1 : 2". This is a very simple if/then statement and can be used any time you have 2 possible results. This is what it means:

whichcharacter = 2 -> If whichcharacter is equal to 2
? 1 -> Then return 1
: 2 -> If not, return 2

Because I wrote the function in the action to set whichcharacter, the result is, whichcharacter is set to the return value. So, if whichcharacter is currently 2, whichcharacter is set to 1. If not, it is set to 2.

Well, that was a long one but I hope it helps. Good luck with your project.



are you god? thanks a lot, it is so much better and easy now, i learned a lot from what you did just now, you have my thanks.sorry for any trouble you went to make this masterpiece. :DD


but i found a problem, you see i wanted to only gain character 2(monster) when i press my E near the ovo object, but when i do that, it created a totaly diferent character, so when i press space my camera goes to the character 2(which is out of the way, meaning..in the blank space where i cant see him) instead of the new spawned object
B
5
S
1
Posts: 77
Reputation: 754

Post » Tue May 06, 2014 5:39 pm

I would have to see the capx to get an idea of what is going on.

[EDIT] NVM, I see what you mean on the version I already have. Looking into it now.

[EDIT] OK, that was an easy fix. I added a variable called, "MonsterExists" 0 for false and 1 for true. I destroyed the off screen monster on start of the layout (you could also just move this monster into view instead of destroying and recreating but this took the fewest steps to get your current set up working) and I added a few actions to your create event including setting MonsterExists to 1 and moved the monster disable action into this event instead of the start of layout.
You do not have the required permissions to view the files attached to this post.
B
38
S
12
G
11
Posts: 331
Reputation: 7,712

Post » Tue May 06, 2014 7:56 pm

yes, its perfect now, again, my thanks.
B
5
S
1
Posts: 77
Reputation: 754


Return to How do I....?

Who is online

Users browsing this forum: Demkamen and 12 guests