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.
Please share some code :D We can understand your issue much better if you share code.
– dorpelegAs @dorpeleg says, we need to see some code. In particular we need anything that assigns or modified currentPosition.
– robertbuYou 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.
– robertbudoes it instantiate on the same place?
– Auggie