- Home /
What is wrong with my CharController script?
var normalSpeed:float=6.0; private var speed:float=normalSpeed; var runSpeed:float=12.0; private var jumpSpeed:float=speed*1.7; var gravity:float=20.0; private var walkTime:int=0; private var moveDirection:Vector3=Vector3.zero; static var grounded:boolean=false; private var controller:CharacterController; private var flags:CollisionFlags;
function Start(){ animation.wrapMode=WrapMode.loop; animation["run"].layer=-1; animation["walk"].layer=-1; animation["idle"].layer=-1; animation.SyncLayer(-1); animation["jump"].layer=10; animation["jump"].wrapMode.Once; animation.SyncLayer(10); animation.Stop(); animation.Play("idle");
function FixedUpdate();{ if(grounded){ moveDirection=new Vector3(Input.GetAxis("Horizontal"),0,0); moveDirection*=speed; if (Input.GetButton("Jump")){ moveDirection.y=jumpSpeed; animation.CrossFade("jump"); }
} moveDirection.y-=gravity*Time.deltaTime; controller=GetComponet(CharacterController); flags=controller.Move(moveDirection*Time.deltaTime); grounded=(flags & CollisionFlags.CollidedBelow) !=0; if(Input.GetAxis("Horizontal")>.2 || Input.GetAxis("Horizontial")<-.2){ if(walkTime>40){ animation.CrossFade("run"); speed=runSpeed; }else{ walkTime++; animation.CrossFade("walk"); speed=normalSpeed; } jumpSpeed=speed*1.7; }else{ walkTime=0; animation.CrossFade("idle"); } }
@script RequireComponet(CharacterController)
It's all written on one line.
1) Use the 101/010 button to format code so we can read it.
2) Explain what it should do.
3) Explain what it is doing - in detail - including errors.
4) Profit! Hey look, no ??? step.
"Component" is spelled like that <=
Answer by CaioRosisca · Oct 17, 2012 at 10:19 PM
Try to edit your question posting the code as a code snipet..so its a bit more organized and easy to understand..try also to post what errors you are getting..or what isn´t happening as expected
Your answer
Follow this Question
Related Questions
Stay on top of the ground 1 Answer
Setting Scroll View Width GUILayout 1 Answer
How do I disable Script on FP Controller? (Solved) 2 Answers
Character strafing problem (javascript) 0 Answers
Can someone help me fix my Javascript for Flickering Light? 6 Answers