I am working on a game in which i am moving the character continuously in one direction. For doing so i am using character controller on the character but still some jerks are appearing in the game play.
var c : CharacterController;
var speed : float;
var jumpspeed : float;
var moveDirection : Vector3;
var vel : Vector3;
function Start()
{
c=GetComponent(CharacterController);
}
//
function FixedUpdate ()
{
moveDirection=transform.TransformDirection(Vector3.forward);
moveDirection*=speed;
if(c.isGrounded)
{
if(Input.GetButton("Jump"))
{
vel.y=3.5;
}
}
else
{
vel.y+=Physics.gravity.y*Time.deltaTime;
}
moveDirection+=vel;
c.Move(moveDirection*Time.deltaTime);
}
could you please share some code? I have been unable to make something move across the 2D screen smoothly. I’m just moving some obstacles for my main character to avoid, they probably don’t need their own character controllers but I’m getting desperate.