I’m still a bit new to unity, so my apologies if this is a stupid question…
I have successfully imported my own character into Unity, and set up the animations and controls. My only problem is, as soon as I click the play button, my character drops through the terrain into the middle of nowhere, while the spring follow camera zooms out and starts shaking pretty bad. I looked into the “dropping into the middle of nowhere” issue, and found that if I parented my character to an empty game object then my character stayed on the terrain. However, it still gets stuck in place. The animations still work, but I can’t move anywhere. When I disable the animation script, everything runs perfectly, I just don’t have any animations. But the moment I re-enable the animation script, I get stuck again and the camera problems come back. Does anyone know how to fix all this? Maybe the animation script I’m using doesn’t work with the character movement script?
These are the 2 scripts. Once again, I’m still kinda new to this, so it could just be something obvious…
Character controls/movement:
var walkSpeed:float = 1.0;
var turnSpeed:float = 1.0;
var runSpeed:float = 1.0;
function Update()
{
if(Input.GetButton("Forward"))
{
transform.position += transform.forward * walkSpeed * Time.deltaTime;
}
if(Input.GetButton("Backward"))
{
transform.position += -transform.forward * runSpeed * Time.deltaTime;
}
if(Input.GetButton("Left"))
{
transform.eulerAngles.y += -turnSpeed * Time.deltaTime;
}
if(Input.GetButton("Right"))
{
transform.eulerAngles.y += turnSpeed * Time.deltaTime;
}
}
Animations:
function Start ()
{
// Set all animations to loop
animation.wrapMode = WrapMode.Loop;
// except these
animation["GetBalloon"].wrapMode = WrapMode.Once;
animation["Throw"].wrapMode = WrapMode.Once;
animation["Idle"].wrapMode = WrapMode.Once;
// Put idle and walk into lower layers (The default layer is always 0)
// This will do two things
// - Since shoot and idle/walk are in different layers they will not affect
// each other's playback when calling CrossFade.
// - Since shoot is in a higher layer, the animation will replace idle/walk
// animations when faded in.
animation["GetBalloon"].layer = 1;
animation["Throw"].layer = 3;
animation["Run"].layer = 1;
animation["Idle"].layer = 2;
// Stop animations that are already playing
//(In case user forgot to disable play automatically)
animation.Stop();
}
function Update () {
// Based on the key that is pressed,
// play the run animation or the idle animation
if (Mathf.Abs(Input.GetAxis("Forward")))
animation.CrossFade("Run");
else
animation.CrossFade("Idle");
// Throw balloon
if (Input.GetMouseButtonDown(0))
animation.CrossFade("GetBalloon");
if (Input.GetMouseButtonUp (0))
animation.CrossFade("Throw");
}
SETTINGS ON CHARACTER INSPECTOR:
Spring Follow Camera (Script):
Target = Sphere (Transform) (This is an invisible empty game object that I have parented to my character, just so I can adjust the camera position behind it.)
Distance = 4
Height = 1
Smooth Lag = 84.88175
Max Speed = 10
Snap Lag = 0.3
Clamp Head Position Screen Space = 100.5553
Line of Sight Mask = Nothing
Move Around (Script):
Walk Speed = 14.73448
Turn Speed = 133.6174
Run Speed = 0 (I don’t use this, as the character can only run, not walk, so I use the Walk Speed for that.)
Capsule Collider:
Is Trigger = No
Material = None (Physic Material)
Center = (X = 0) (Y = -0.1987256) (Z = 0)
Radius = 0.3199999
Height = 1.907082
Direction = Y-Axis
Rigidbody:
Mass = 1
Drag = 0
Angular Drag = 0
Use Gravity = Yes
Is Kinematic = No
Interpolate = None
Collision Detection = Discrete
Constraints:
Freeze Position = (X = Yes) (Y = No) (Z = Yes) (This is to prevent my character from sliding down hills even when not running, and even when they’re all unchecked, my immobility problem persists.)
Freeze Rotation = (X = Yes) (Y = Yes) (Z = Yes) (This is to prevent my character from bouncing all over the place, and even when they’re all checked, I can still move around, as long as my animations are disabled.)
Player Animations (Script) (No Settings)
Run Faster (Script) (No Settings)
Throw Faster (Script) (No Settings)
(The last 2 scripts are simply there to increase the speed at which the “Run” and “Throw” animations play.)