Hi, I’m trying to make a point and click interface (trying to build a prototype for a more modern 2.5D-ish point and click adventure game).
I’m not much of a coder and there are probably all kinds of things wrong with my code so far, but I’ll figure them out.
Here is my code :
function Awake(){
var moveDirectionc = Vector3.zero;
var targetPoint = Vector3.zero;
}
var speed = 0.35;
function Update () {
if (Input.GetMouseButtonDown(0)){
moveaa();
}
}
function moveaa() {
var screenSpace = Camera.main.WorldToScreenPoint(transform.position);
var controller : CharacterController = GetComponent(CharacterController);
var transformx = this.transform.position.x;
var targetPoint = Camera.main.ScreenToWorldPoint(Vector3(Input.mousePosition.x,screenSpace.y,screenSpace.z));
moveDirectionc = Vector3(targetPoint.x - transformx,0,0);
moveDirectionc = Vector3.Normalize(moveDirectionc)*speed/100;
moveDirectionc.y = -1;
while (Mathf.Abs(transformx - targetPoint.x) > 0.02){
controller.Move(moveDirectionc);
transformx = this.transform.position.x;
yield WaitForFixedUpdate;
if (Input.GetMouseButtonDown(0)){
break;
}
}
}
The code works (I only care about moving the main character on the X axis). The only problem is, it’s not framerate independent. On an older computer were the framerate is somewhat choppy, the main character moves really slowly.
And here is my question: shouldn’t yield WaitForFixedUpdate; take care of that? Doesn’t this line make the while loop repeat at the fixed rate?