- Home /
Character snapping to new position upon "play."
Just to preface this question, I'm extremely new to Unity, so this may not sound like the most intelligent question ever. Anyway.
I have a 7 characters in my scene, lined up side by side. They are using the same Avatar and Character controller script. Everything is identical except the fact that I am using two different meshes. When I hit the play button, one of the meshes snaps down beneath the ground plane for it's starting position, yet in the Scene window is positioned correctly. Does anyone happen to know why this is, or where to look? They have the exact same pivot points and their rigs are identical.
Thanks so much.
Unlikely but you never know - make sure none of its colliders are intersecting with the ones on either side before you play the scene.
Colliders are not intersecting, but thank you nonetheless for that.
I do have a script applied to it. Ugh, I wish I understood this better. This is a scene that I have inherited from someone else, and I am trying to change it around to use for a different activity. This is what the script looks like. I do not have a scripting background, so bare with me please. (removed variables introduction to reduce character count). HERE IS THE SCRIPT
Can you please post your script here on the page using the "code sample" button?? Just type it in and select it then press Ctrl+k and it will format it right. I can't open that file from my office computer.
Let's see if this works...
#pragma strict
var theDwarf : GameObject;
var detect : detector;
var scriptHolder : GameObject;
var nowActive : boolean;
var activeNow : String;
var intersecting : boolean;
var lookAtPoint : Vector3;
var dwarfSelected : boolean;
var markedCorrect : boolean;
var whereAmI : GameObject;
var isPivoted : boolean;
var isPivoted2 : boolean;
var pivot : Vector3;
var entrance : Vector3;
var hidingPlace : Vector3;
var shortName : String;
var startingPointPos : Vector3;
var startingPointRot : Quaternion;
function Start(){
scriptHolder = GameObject.Find("00-scripts");
detect = scriptHolder.GetComponent(detector);
lookAtPoint = Camera.main.transform.position;
lookAtPoint.y = 0.0;
pivot = GameObject.Find("pivot").transform.position;
entrance = GameObject.Find("Entrance").transform.position;
hidingPlace = GameObject.Find("Hiding Place").transform.position;
theDwarf = gameObject;
startingPointPos = gameObject.transform.position;
startingPointRot = gameObject.transform.rotation;
}
function On$$anonymous$$ouseDown(){
if (!detect.is$$anonymous$$oving)
{
detect.cutAckAnim = true;
detect.activeDwarf = null;
detect.activeSlot = null;
nowActive = false;
}
}
function On$$anonymous$$ouseUp () {
if (!detect.is$$anonymous$$oving)
{
detect.cutAckAnim = false;
detect.activeDwarf = theDwarf;
nowActive = true;
detect.activeNow = gameObject.name;
theDwarf.transform.LookAt(lookAtPoint);
dwarfSelected = true;
shortName = theDwarf.name.Substring(0, theDwarf.name.length-6);
detect.shortName = shortName;
}
}
function Update()
{
if (detect.goingTo$$anonymous$$ovies && !isPivoted)
{
theDwarf.transform.LookAt(pivot);
theDwarf.transform.position = Vector3.$$anonymous$$oveTowards(theDwarf.transform.position, pivot, Time.deltaTime * detect.speed);
if (theDwarf.transform.position == pivot)
{
isPivoted = true;
}
}
else if (detect.goingTo$$anonymous$$ovies && isPivoted && !isPivoted2)
{
theDwarf.transform.LookAt(entrance);
theDwarf.transform.position = Vector3.$$anonymous$$oveTowards(theDwarf.transform.position, entrance, Time.deltaTime * detect.speed);
if (theDwarf.transform.position == entrance)
{
isPivoted2 = true;
}
}
if (isPivoted && isPivoted2)
{
theDwarf.transform.LookAt(hidingPlace);
theDwarf.transform.position = Vector3.$$anonymous$$oveTowards(theDwarf.transform.position, hidingPlace, Time.deltaTime * detect.speed);
}
if (theDwarf.transform.position == hidingPlace)
{
detect.areDwarvesInside = true;
}
if (detect.isReset)
{
gameObject.transform.position = startingPointPos;
gameObject.transform.rotation = startingPointRot;
}
}