- Home /
why is my character suddenly move when a scene is loaded?
I wanna get rid of this thing. my character enters a portal and I clicked ok to load the level and the moment my character lands on the scene, it start to move. I just want it to stand still on the spawn point and move only if I told it so or click somewhere in the map. do you know whats the problem.. thanks here is the code:
var smooth:float; // Determines how quickly object moves towards position var isWalking : boolean; var lastP; var move; var pressed: boolean; var standing : boolean; var objectP ; private var targetPosition:Vector3;
function Start() { animation.Stop(); animation.Play("idle"); // this stops Unity from playing the character's default animation. standing = spawnPointScript.standing; objectP = spawnPointScript.objectP; }
function Update () { pressed = false;
if(pressed== false)
{
if(Input.GetKeyDown(KeyCode.Mouse1))
{
smooth=5;
var playerPlane = new Plane(Vector3.up, transform.position);
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hitdist = 0.0;
if (playerPlane.Raycast (ray, hitdist)) {
var targetPoint = ray.GetPoint(hitdist);
targetPosition = ray.GetPoint(hitdist);
var targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
transform.rotation = targetRotation;
}
}
move =transform.position = Vector3.MoveTowards(transform.position, targetPosition, Time.deltaTime*smooth); if(lastP != move) { if(!isWalking){ isWalking= true; animation.Play("walk");
}
}
else
{
if(isWalking)
{
isWalking = false;
animation.Play("idle");
}
}
lastP =move;}
pressed = true;
}
Well, there's no way to know without knowing what your character is, and how it moves!
it moves using mouse click.... I have a script called mouse click..
I just want my character to stay where the position of the object where it landed
Ok, again. What we know is you have a script called "$$anonymous$$ouseClick". We have no idea how it works or how it's implemented. If it's the only script that moves the character it's highly possible that this script cause the movement.
With the information you've given, can you spot the error in this black box?
/---$$anonymous$$ouseClick---\
| |
| |
| |
| E |
| |
\----------------/
Answer by $$anonymous$$ · Feb 03, 2012 at 12:57 PM
As others have said above, it's very hard to be sure what the problem is without more info. However, I recently ran into a very similar sounding problem where an object would immediately jump to (0,0,0) on level-load. That was because the object (by default) had the 'Animation' checkbox enabled, yet there are no animations in its fbx (model file). Is it possible that this is happening, or even perhaps that the model is executing its default animation (that you have actually defined in the model file), causing the movement?
my animation checkbox is disabled. When the level is loaded, my character will walk going to bottom-left slowly even if i am not clicking.
additional info.. my character is moving towards the position where it is facing before the level is loaded. example: if my character is facing up, it will move upward