|
Post by RonnyDance on May 20, 2017 9:14:47 GMT
First of all hello everyone, I am pretty new and proud owner of the Shooter Template and had a little bit of time to play with it. Really amazing product and happy to see which features are coming in the future.
To my question: I would like to change the Character Model of my player IG using a button. Think of a Human, which can transform to a werewolf or something like that. For that I created a pretty simple script (I am not a C# expert) which just activates / deactivates models which are used for the player without any particle effects etc:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class ChangeModel : MonoBehaviour {
public GameObject modelA; public GameObject modelB; public GameObject modelC;
private int modelNumber;
void Start () { modelNumber = 1; modelB.SetActive(false); modelC.SetActive(false); }
void ModelSwitch(){ if(modelNumber == 1){ modelA.SetActive(false); modelB.SetActive(true); modelNumber = 2; }else if(modelNumber == 2){ modelB.SetActive(false); modelC.SetActive(true); modelNumber = 3; }else if(modelNumber == 3){ modelC.SetActive(false); modelA.SetActive(true); modelNumber = 1; } }
void Update () { if (Input.GetButtonDown ("A")){ ModelSwitch(); }
} }
Pretty simple. If I put the Models as child objects of the vThirdPersonShooter where the default model is hold, I have the problem that the model does not animate because it has no controller. If I duplicate the vThirdPersonShooter prefab using the different model and use this in the script as a second model, I have the problem that the default one is overwritten and I only see the second.
So is there a clean and good way to change Playermodels which are used by the Invector Template? Since the Invector Wizard always wants and take on Model of the player I am asking myself how easy it would be to support multiple and swap them through Keypress? Of course in the future own animations / animationcontrollers for the different model would be great since a human moves different than a werewolf - or on model can fly the other can't etc - , but for the beginning a simple swap would be cool.
Thanks a lot for your time. Cheers Ronny
|
|
|
Post by tharindu on May 21, 2017 6:54:07 GMT
First of all hello everyone, I am pretty new and proud owner of the Shooter Template and had a little bit of time to play with it. Really amazing product and happy to see which features are coming in the future. To my question: I would like to change the Character Model of my player IG using a button. Think of a Human, which can transform to a werewolf or something like that. For that I created a pretty simple script (I am not a C# expert) which just activates / deactivates models which are used for the player without any particle effects etc: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class ChangeModel : MonoBehaviour {
public GameObject modelA; public GameObject modelB; public GameObject modelC;
private int modelNumber;
void Start () { modelNumber = 1; modelB.SetActive(false); modelC.SetActive(false); }
void ModelSwitch(){ if(modelNumber == 1){ modelA.SetActive(false); modelB.SetActive(true); modelNumber = 2; }else if(modelNumber == 2){ modelB.SetActive(false); modelC.SetActive(true); modelNumber = 3; }else if(modelNumber == 3){ modelC.SetActive(false); modelA.SetActive(true); modelNumber = 1; } }
void Update () { if (Input.GetButtonDown ("A")){ ModelSwitch(); }
} }
Pretty simple. If I put the Models as child objects of the vThirdPersonShooter where the default model is hold, I have the problem that the model does not animate because it has no controller. If I duplicate the vThirdPersonShooter prefab using the different model and use this in the script as a second model, I have the problem that the default one is overwritten and I only see the second. So is there a clean and good way to change Playermodels which are used by the Invector Template? Since the Invector Wizard always wants and take on Model of the player I am asking myself how easy it would be to support multiple and swap them through Keypress? Of course in the future own animations / animationcontrollers for the different model would be great since a human moves different than a werewolf - or on model can fly the other can't etc - , but for the beginning a simple swap would be cool. Thanks a lot for your time. Cheers Ronny Interesting question. I'll try to do the same and see what I come up with. Btw glad you got this controller man. It's evilangel89 from the gaia forum btw :D
|
|
|
Post by shadex on May 22, 2017 4:33:00 GMT
To my question: I would like to change the Character Model of my player IG using a button. Think of a Human, which can transform to a werewolf or something like that. For that I created a pretty simple script (I am not a C# expert) which just activates / deactivates models which are used for the player without any particle effects etc: Thanks a lot for your time. Cheers Ronny How do you want the animations and particle effects to work? Do you want to play an animations, and half way through start a particle effect and swap the models after the particle effect? Or do you want the animation to play, call the particle effect and then swap? Or do you just want to ignore the animation and just instantiate a particle and swap body's? It really depends on how much control do you want on the animations, and how do you want to set it up. That's going to determine what method you want to use.
|
|
|
Post by RonnyDance on May 22, 2017 7:38:18 GMT
Hey evilangel89 nice to see you around Good to see some known people in this forums As I mentioned in the first post, for me the most easiest way - changing model without animation and particle effect - would be fine for the beginning, to know where to put other models and to see how a normal / simple swap works with the Controller. Of course after that we would come to the serious stuff where I see this workflow: - Press Button - Play Spell Cast Animation which last 2-3 Seconds - Play Particle Effect like Smog / Explosion - Swap the Controller / Model. I am writing swap the controller, because the new Model should have different animations for moving / jumping / sprinting etc. Jumping higher, sprinting faster, perhaps using the fly addon which is posted here in the forums etc. So it should be different to the normal / default one in many cases not just in Animations. Thats why I thought having two controllers in the scene would be a good idea, where the second controller is disabled by default and you can swap to this one by pressing the key. But again, for me it didn't work having two controllers in the scene. Thanks guys for your replies. Cheers Ronny </abbr>
|
|
|
Post by tharindu on May 22, 2017 9:45:59 GMT
Actually you could insert new animations into the controller without replacing existing ones. All you need is to use a new moveset ID.
Take a look at the animator's blend trees and you'll see they accept a parameter named moveset ID. It's based on this moveset ID that the final animation is selected in most animations.
So you can use the same animator and the same animator controller, you can simple change the movset ID. As for having different speeds and such for the animations, you can check out the demoscene, where you have a particular script in the controller, that increases the speed of a move set. I recommend checking out those parameters too, without having to swap controllers.
I haven't been able to look at this scenario yet, I'll take a look at it once I am home.
|
|
|
Post by shadex on May 22, 2017 16:14:46 GMT
Hey evilangel89 nice to see you around Good to see some known people in this forums As I mentioned in the first post, for me the most easiest way - changing model without animation and particle effect - would be fine for the beginning, to know where to put other models and to see how a normal / simple swap works with the Controller. Of course after that we would come to the serious stuff where I see this workflow: - Press Button - Play Spell Cast Animation which last 2-3 Seconds - Play Particle Effect like Smog / Explosion - Swap the Controller / Model. I am writing swap the controller, because the new Model should have different animations for moving / jumping / sprinting etc. Jumping higher, sprinting faster, perhaps using the fly addon which is posted here in the forums etc. So it should be different to the normal / default one in many cases not just in Animations. Thats why I thought having two controllers in the scene would be a good idea, where the second controller is disabled by default and you can swap to this one by pressing the key. But again, for me it didn't work having two controllers in the scene. Thanks guys for your replies. Cheers Ronny </abbr> TheRindu is right, you don't want to swap out the entire controller. Each time you would switch you would be reinitializing the controller, which depending on how you did it would either slowdown the game overall, or would dramaticly slow down the game when you made the switch. So I've actually been working on some stuff similar to this. What i did was i made 2 scripts. A monobehavior script that is on the player (same level in the hierarchy as the animator), and a State Machine Behavior on the animation you want to call. Keep the swap function and the input on the monobehavior script that is on the player. Create a new trigger inside the animator called something like "BeastMode" and in the fullbody layer from AnyState add the animation you want and add the transition with a BeastMode condition, and make the input call on that trigger. Now on the StateMachineBehavior you instantiate the particle effect at a certain point in the animation and call the function after that point in the animation. This allows you to do something like 40% in the animation instantiate the particle effect, then 60% into the animation, call function to swap the mesh. You can also set the MoveID on state exit, and later add camera logic on state enter if you want something like the camera to zoom in, or pan around the character when your character changes. The other way, which will do what your asking for, but not much else, is to simply create one script that triggers the animation, waits till the animation is done, then creates the particle effect and swaps the mesh out. The problem that your going to run into with that, is the particle effect and the swap will happen at the same time, so the particle effect won't be able to really hide the mesh swap. Otherwise your kinda cornered into baking the functions into the animation itself, which i personally absolutely hate.
|
|
|
Post by RonnyDance on May 23, 2017 17:03:57 GMT
Thanks so much for your input shadex. I didn't have the time to take a closer look to the animator of the Template but I will do that this days. After that gonna see how I will do those scripts for switching using animation and particle effect. This will take some time since I am not an Unity C# Pro, but well if I have somethin to show I will gonna keep you updated.
Cheers Ronny
|
|
|
Post by yondaime08 on May 24, 2017 3:07:01 GMT
Hey so first off thank you for making such an amazing but simple script. 2nd I got it working to where the characters switch and move just fine! :D 1. Make sure the script is attached to the 1st player character. 2. Take the other 2 models and use invectors "Character creation tool" with both of them as you did for the 1st character. 3. Make sure to have the 2 new characters in the same spot as the 1st player character, so the transformation is smooth. 4. Next deactivate the "Third Person Controller" script for the 2 new characters you made. 5. Then look at the rigidbody scripts for the 2 new characters and make sure all 6 checkboxes for position and rotation are checked. 6. Make sure that both new characters' "Caspule Colliders" are also deactivated. This way the physics wont go crazy. 7. Have model (a) as your 1st character's mesh 8. Same with (B) for the 2nd model's mesh and (C) for the 3rd. 9. Make sure to have whatever "Animator Controller" you want for each model (it can be different for each one.) 10. Save scene and test it.
Because the controller scripts for the other 2 characters has been disabled it won't override anything nor slow down your frame rate. Also this allows for you to use "override controllers" within the "Animator controller for the other 2 models. This way you swap models and have completely different animations for all 3.
I was at this for a good 5 + hrs. if anyone needs help configuring this let me know. You use the code as is and set it up just like I said above and it works! Oh I am using Melee system btw. I don't see why this setup would be any different in the shooter though... Also as far as particle effects why not initiate a prefab within the script and call a delay function it should spawn within the character's location by default from script association.
|
|
|
Post by kevios on Nov 16, 2017 16:47:53 GMT
hi, i try this script with the introduction from yandaime08 but i failed.. i have 1 "hero player character" and 1 "transformed player character" in my hierarchy (i use only 2 characters so i make the script littlebit shorter and delte the 3 player). i do exact all what yandaime08 write down here but when i test it the "hero" can walk and all is fine when i press A then he transform to the "transformed hero" but the "transformed hero" cant move he only walk on the same place and he his postiton is is fixed and when i press A again he dont transform back to the "hero" ... i dont know what i have to do that it works ... can you help me?
|
|