The script is incorrect and I know it. What I am trying to achieve is if I move along the horizontal axis with a speed greater the 0.1 then it will start walking. I am not sure how to do this. PLEASE HELP!!!
var runSpeed : float = 50;
var moveSpeed : float = 0.9;
var walkingSpeed : float = 0.1;
var golemAnimator : Animator;
function Update () {
var runSpeed = Input.GetAxis("Horizontal") * moveSpeed;
moveSpeed *= Time.deltaTime;
transform.position.x += moveSpeed * Time.deltaTime;
golemAnimator.SetFloat("RunningSpeed", runSpeed);
}
Does this help?
var input = Input.GetAxis("Horizontal");
if(input < walkingSpeed || input > walkingSpeed)
{
runSpeed = input*moveSpeed*Time.deltaTime;
transform.position.x += runSpeed;
golemAnimator.SetFloat("RunningSpeed", runSpeed);
}
Maybe you are forgetting about transform.right to perform the horizontal movement. Check this out:
transform.position += transform.right * Input.GetAxis(axisName) * speed * Time.deltaTime;
Where:
- transform refers the player transform;
- speed is a flot like 5.0f, 7.0f, whatever;
- transfomr.right to make it move horizontally.
Try something like that and see the results.