- Home /
Can't do spawning
Hi all!
right now i'm doing simple 2d platformer for learning's sake and this is the code i have for spawning after i get killed by a spike:
function Spawn()
{
animation.Play("DIE");
rigidbody.AddForce(Vector3.down * 200);
transform.position = spawn.position;
++deaths;
}
but i recently discovered the ball always goes to 0,0,0 and not to the spawn.position, why is this?
also, the spawn variable is a variable that gets created at the beginning of the code : var spawn : Transform ; and is left empty and then assigned in unity. Does it make a difference? is there a way to do this by coding? because it would be simpler to handle checkpoints that way.. although this is all irrelevant until i finally manage to do the simple spawning..
It sounds to me like your DIE animation is what is causing the ball to always spawn at 0,0,0.
Try removing or commenting out the animation and see if the problem still remains
he is right - if your animations involve with movement, then you cant make the animated object stay at spawn position, unless if your script only uses rotations. then its = spawn(withouth .position)
Yes! you guys were right! i'll just make the rest of the code wait until the animation stops playing.. but would any of you be so kind as to post that as an answer for me to mark as correct or even kinder and explain me how to add the spawn by scripting? as i could just change the spawn variable to make checkpoints in my game!
Thanks in advance!
Your answer
Follow this Question
Related Questions
LookAt transform plus a y value 1 Answer
varibals coincidence 1 Answer
Move object to raycast point. 3 Answers
how to make a character resume after going into a random battle? 1 Answer
Simplest movement to point possible 2 Answers