Different output speed in different PC [SOLVED]

I was making my game inside Unity, an everything looks and run smoothly in the game view: the characters and AI all moving at the right speed.

And then when I build and run it, everything moves extremely fast! When I play the built game in my PC, all the characters move double the speed I originally made inside Unity; while in my laptop, the game was slow… like hell. The velocity of the characters and AI inside was so mess up that their animation do not move in accordance to their speed, and everything looks really weird.

This is not the first time it has happen to me, the previous racing game which i made also get the same problem. Help me out here!

I try to build using the web player, and it runs very good and exactly as it is in unity…

But the standalone problem is still occurring…

Did you use Update() where you should have used FixedUpdate()?

Are you making your moves time dependant, instead of frame dependant, by using Time.deltaTime ?

FixedUpdate is only for physics, it’s not a good substitute for correctly making your game framerate-independent.

–Eric

I use Update() all the time. is there a difference between them?

I use deltaTime all the time too. Aren’t they all the same?

But one thing is that my AI doesn’t really use deltaTime a lot. Anyway, this is the script, just have a look and tell me what’s wrong:

//This is my first AI attempt, so it's not gonna be that good...

//Two "waypoint", in which one of them is the main character. 
var waypoint : Transform[];
var mainTarget : Transform;

private var waypointNo : int;
private var walkSpeed : float = 0.1;
private var gravity : float = 100.0;
private var moveDirection : Vector3 = Vector3.zero;
private var charController : CharacterController;
private var currentTarget : Transform;
private var playerIsHit : boolean;
private var movementType : String;
private var playerInDark : boolean;

function Start () {
	//Start with the first waypoint.
	waypointNo = 0;
	charController = GetComponent(CharacterController);
	animation.wrapMode = WrapMode.Loop;
	walkSpeed = 0.0;
	playerIsHit = false;
}

function Update () {
	//If the player is within the dark area.
	playerInDark = PlayerScript.playerInDark;
	
	if (playerIsHit) {
		currentTarget = mainTarget;
		movementType = "run";
		walkSpeed = 0.5;
	}
	else {
		currentTarget = waypoint[waypointNo];
		movementType = "walk";
		walkSpeed = 0.1;
	}
	
	var target : Vector3 = currentTarget.position;
	moveDirection = (target - transform.position);
	
	if (moveDirection.magnitude > 5) {
		animation.CrossFade(movementType);
	}
	else {
		walkSpeed = 0.0;
		animation["walkStop"].wrapMode = WrapMode.Once;
		animation.CrossFade("walkStop");
		waypointNo++;
	}
	
	if (waypointNo > waypoint.length - 1) {
		waypointNo = 0;
	}

	RotateToTarget(currentTarget);
	
	moveDirection = Vector3(0,0,walkSpeed);
	moveDirection = transform.TransformDirection(moveDirection);
	moveDirection.y -= gravity * Time.deltaTime;
	charController.Move(moveDirection);
}
//I added a box collider to the AI as its "field of view".
function OnTriggerEnter (collided : Collider) {
	if (collided.gameObject.tag == "player"  playerIsHit == false) {
		if (playerInDark) {
			playerIsHit = false;
		}
		else {
			playerIsHit = true;
		}
	}	 
}

function OnTriggerExit (collided : Collider) {
	if (collided.gameObject.tag == "player"  playerIsHit == true) {
		playerIsHit = false;
	}
}

function RotateToTarget (targeted : Transform) {
	var rotate = Quaternion.LookRotation(targeted.position - transform.position);
	var damp = 2.0;
	
	transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp);
}

Which part should I change? The Update part?
I try changing it to FixedUpdate, but the character doesn’s seems to be moving…

P.S. If you want an example of the game, I can send it to you. See if it works out fine in your PC…

You need to multiply your moveDirection variable by Time.deltaTime.

At a glance, probably

moveDirection = Vector3(0,0,walkSpeed * Time.deltaTime);

ありがとう!!! Mr. Callahan.44, thanks a lot, it works!!! You just save my day!!!

And now I understand a little bit more about Unity scripting now…

Hey, i know you wrote this some time ago, but i have the same problem. My problem is I did all of this with Time.deltaTime. When i put the player speed on 1500 it feels nice. When I export it and install it on my phone 1500 is MEGA fast. How can i fix this? How can I make 1500 the same speed??