Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by Maielstrom · Mar 18, 2013 at 08:13 PM · instantiatetransformpositionragdoll

Instantiating at wrong values

I have a zombie enemy, when the enemy dies, I am trying to instantiate a ragdoll version over it. The instantiating is working out fine, it applies to correct transform values, however these values applied to the ragdoll mesh are entirely outside of the map. Example being the zombie enemy has a y value of ~161 (and is on the map), but this same value on the ragdol mesh is way below the map (ragdoll needs a value in the 800s to be close to where the map is). Anyone have an idea what is happening here? Thanks

Edit: Sorry about that! The instantiating code is as follows:

               currentPosition = transform.TransformPoint(Vector3.zero);
               GameObject Doll;
             Doll = Instantiate(Rag, currentPosition, transform.rotation) as GameObject;

Rag is the Ragdoll model declared at the beginning as a GameObject currentPosition is declared as a vector3 at the beginning. currentPosition is created as transform.TransformPoint(Vector3.zero);

I originally had transform.position in instantiate but when it didn't work, I figured I'd get the zombie's current position and put that in instead. Please let me know if there is any other info which would help to solve this one. Thanks again!

Full code:

public int ZombieTotalHealth = 5; public int ZombieLives = 1; private int ZombieHealth; public GameState gameController;

 public GameObject Rag;
 private Vector3 currentPosition;
 
 // Use this for initialization
 void Start () {
         ZombieHealth = ZombieTotalHealth;
 }
 // Update is called once per frame
 void Update () {
     currentPosition = transform.TransformPoint(Vector3.zero);
     if(ZombieHealth <= 0)
     {   
     Die();
     }    
 }
 
 public void ApplyDamage(int damage){
     
 ZombieHealth -= damage; 
  
     
 }
 
         public void Die (){
             GameObject Doll;
             Doll = Instantiate(Rag, currentPosition, transform.rotation) as GameObject;
             Destroy(gameObject);
             
             
 }

 }


Forgot to mention that this script is attached to the zombie, and the ragdoll is just the ragdoll mesh with no current script on it, it should just be instantiating at the point where the zombie was.

I tried using transform.position too, but that gave the same issue. The ragdoll mesh inherits the correct values from the zombie mesh, but for some reason the ragdoll coordinates with those values are outside the map. As said up above, the zombies have a y value of ~161, but the ragdoll needs a value in the 800s to be at the same y position as the zombies. - This is after the ragdoll is instantiated, the master ragdoll is at the appropriate location if given a y value of ~161.

Comment
Add comment · Show 4
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 dorpeleg · Mar 18, 2013 at 08:48 PM 0
Share

Please share some code :D

We can understand your issue much better if you share code.

avatar image robertbu · Mar 18, 2013 at 10:09 PM 0
Share

As @dorpeleg says, we need to see some code. In particular we need anything that assigns or modified currentPosition.

avatar image robertbu · Mar 18, 2013 at 10:54 PM 0
Share

You need the position of the zombie, but, unless this script is attached to the zombie, there is nothing here that gives that position. If this script is attached to the zombie, then transform.position is the correct value. But you say "get the zombie's position," so I'm not sure how you have your object/scripts structured.

avatar image Auggie · Mar 19, 2013 at 12:41 AM 0
Share

does it instantiate on the same place?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Auggie · Mar 19, 2013 at 12:32 AM

I don't know what effect you are trying to achieve here but if you just want it to be instantiated where your zombie dies, then i see no reason why not to use this code:

 public void Die (){
 
          GameObject Doll = Instantiate(Rag, transform.position, transform.rotation) as GameObject;
          Destroy(gameObject);
 }

i don't think you really need to use transform.TransformPoint because transform.position is set to world space already. while transform.TransformPoint, if i'm not mistaken, uses the value of your localPosition to worldPosition. which would explain why your position vector is a bit off

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 Maielstrom · Mar 19, 2013 at 04:20 PM

I found out what the problem was! I had the zombie ragdoll model floating in space, causing it to fall straight down into an endless void. I created a "box" to hold it in using planes so it remains at the spot I put it, and now it spawns in the correct place where it's zombie host dies

Comment
Add comment · Show 5 · 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 dorpeleg · Mar 19, 2013 at 04:32 PM 0
Share

That should not happen.

Unless your ground has no colliders.

avatar image Maielstrom · Mar 20, 2013 at 02:22 AM 0
Share

The instantiated ragdolls are spawned inside the map. The ragdoll which was falling was the master ragdoll which is cloned at the time of instantiation. I put the master one outside of the map (as this is how I was taught to deal with cloning/instantiating), and thus it just fell at the start as there was nothing underneath it

avatar image Auggie · Mar 20, 2013 at 02:51 AM 0
Share

make your ragdoll into a prefab. that is: drag it from the heirarchy view panel and put it in a folder on the project view panel. and make that prefab as the gameobject to be instantiated. then delete the ragdoll on heirarchy

avatar image Maielstrom · Mar 20, 2013 at 03:25 AM 0
Share

Wow, never knew that one! Thanks, definitely makes things a lot easier

avatar image Auggie · Mar 21, 2013 at 12:15 AM 0
Share

i hope it helps

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

12 People are following this question.

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

Related Questions

I need help with the location of instatiated objects on the scene and correct interaction with this 2 Answers

Copy position from one object to another on one axis 0 Answers

How can I Instantiate a prefab (projectile) consistently from the character? 0 Answers

Instance child global position 1 Answer

How to instantiate object at particular location 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