Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by DragonFang17 · May 27, 2017 at 02:32 PM · prefabcharacter

Character Change Within Level

I'm sure you guys know of this in games, where a player's character is in a beat streak fighting enemies and then is able to enter a rage mode or something.

What I need to figure out is this: I have a character that I want to change form when the meter is full. The concept would be changing one character prefab into another and have the meter on a time based decrease. When the meter is empty I want the player to revert back to the first form. The two character prefabs have a separate armature, build, and animations. I want to avoid parenting the second character prefab to the first one because I had issues with the character controller doing that.

How would I go about doing this?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by DragonFang17 · Dec 03, 2017 at 03:12 PM

This is what I was able to come up with and it works fine:

 public Rigidbody nextForm;
 Rigidbody instantiatedNextForm;
 public GameObject tempTeleport;
 public Transform player;

I have a separate game object away from the level platform out of view from the player and named/tagged it tempTeleport

  void SetTeleport() {
             tempTeleport = GameObject.FindWithTag ("tempTeleport");
     }

I have the instantiated second prefab spawn in to the first prefab's position and rotation after the meter is filled. Then right after I had the first prefab change it's transform to the tempTeleport game object's position with the controls disabled.

  instantiatedNextForm = Instantiate (nextForm, player.position, player.rotation) as Rigidbody;
     Vector3 playerPosition = (player.position = tempTeleport.transform.position);
     
     GameObject.Find ("Form1");
     if (GameObject.Find ("Form1") != null) {
             GameObject.Find ("Form1").GetComponent<CharacterControlForm1> ().enabled = false;
     }

There's a separate camera parented to the second prefab so I didn't have to worry about the view messing up. Any newly added camera's in the game scene just overlap each other.

The meter then decreases and the second prefab has it's controls. When it runs out, the first player prefab's transform goes right back to the second one, I have the second prefab destroyed, and enable the first prefab's controls, and start it all over again when the meter is filled.

 Vector3 playerPosition = (player.transform.position = instantiatedNextForm.transform.position);
 Destroy (instantiatedNextForm.gameObject);
 
 GameObject.Find ("Form1");
 if (GameObject.Find ("Form1") != null) {
         GameObject.Find ("Form1").GetComponent<CharacterControlForm1> ().enabled = true;
 }

I dislike answering my own questions, but I'm self taught with programming. I will eventually solve it.. Thank you all who put in their answers. It's very much appreciated! :)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by FM-Productions · May 27, 2017 at 03:12 PM

Hi,

how about having both characters instantiated in the scene and set them to active/inactive as you need. gameObject.setActive(). Of course, both character prefabs would have to be able to react to user input. Another way I can think of is to have an InputManager and you call certain actions on either your first or second character, based on which one is active. You do not have to deactivate a character gameobject. maybe it is enough to move them out of the cameraview.

Another possibility is to have them controlled both at the same time (both have the same root transform, so the always are in the same place) but render only one of them. Collisions against other characters should only be performed with the visible character.

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DragonFang17 · Jun 14, 2017 at 02:14 PM 0
Share

@Eicher But having both of those prefabs together that have colliders would be messy, one would knock the other out of place and controlling both at the same time would make one of them wonder off away from the previous one @_@

avatar image Shadowskull1247 DragonFang17 · Jun 25, 2017 at 03:10 AM 0
Share

@DragonFang17 Couldn't you just make a script to temporarily disable the collider of the unrendered prefab? Here is an example code that may help:

var YourGameObject : GameObject

var Collider:Collider=Collider.GetComponent("$$anonymous$$esh Collider");

if(YourGameObject.Renderer.isVisible) Collider.enabled = !Collider.enabled;

(The code is untested, so the if statement may not work, but this is just an example.)

avatar image Rickyinjp DragonFang17 · Jun 25, 2017 at 04:15 AM 0
Share

When an object is inactive, all its components are also inactive (this includes colliders). You don't need any special script for the inactive object's colliders to be ignored.

avatar image DragonFang17 DragonFang17 · Sep 01, 2017 at 07:36 PM 0
Share

I'm still puzzled on how I can have this feature in my game :/

Show more comments
avatar image DragonFang17 · Oct 02, 2017 at 05:13 PM 0
Share

Okay, what about parenting a prefab that was spawned in through instantiation, how would I parent the first playable game object to the second spawned in one?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can skeletal animation be applied to a prefab? 0 Answers

A question about unity prefabs and their animations.. 0 Answers

How to save the player? 1 Answer

how can you make a wrapper class for a character? 1 Answer

Destroying & Then Spawning Quickly 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges