I’m having a hard time making my player object taller so it doesn’t look as if you’re playing a little kid. Everytime I scale my object higher, it keeps shrinking once I press play. Any ideas?
Maybe you are setting its scale at start somewhere. Is it childed to another object?
I actually fixed the problem by deleting the current player controller and adding a new one. However, when I added back the ‘sprint’ script, the controller kept shrinking again. So I deleted it and it worked. Kinda sad since I can’t run now.
Can you post the sprint script since it seems to be the culprit?
using UnityEngine;
using System.Collections;
public class Sprint : MonoBehaviour
{
public float walkSpeed = 7; // regular speed
public float crchSpeed = 3; // crouching speed
public float runSpeed = 20; // run speed
private CharacterMotor chMotor;
private Transform tr;
private float dist; // distance to ground
// Use this for initialization
void Start ()
{
chMotor = GetComponent();
tr = transform;
CharacterController ch = GetComponent();
dist = ch.height/2; // calculate distance to ground
}
// Update is called once per frame
void FixedUpdate ()
{
float vScale = 1.0f;
float speed = walkSpeed;
if ((Input.GetKey(“left shift”) || Input.GetKey(“right shift”)) chMotor.grounded)
{
speed = runSpeed;
}
if (Input.GetKey(“c”))
{ // press C to crouch
vScale = 0.5f;
speed = crchSpeed; // slow down when crouching
}
chMotor.movement.maxForwardSpeed = speed; // set max speed
float ultScale = tr.localScale.y; // crouch/stand up smoothly
Vector3 tmpScale = tr.localScale;
Vector3 tmpPosition = tr.position;
tmpScale.y = Mathf.Lerp(tr.localScale.y, vScale, 5 * Time.deltaTime);
tr.localScale = tmpScale;
tmpPosition.y += dist * (tr.localScale.y - ultScale); // fix vertical position
tr.position = tmpPosition;
}
}
To me it looks like you are always calling and adjusting the localScale of tr. Plus both values ultScale and tmpScale = tr.localScale.y. This seems useless.