- Home /
2D SideScroller Controller Script :/
Hello, iam new at unityscript, so i need to help from you, guys. I want make powerfull sidescroller platform style game, with story-line, logic puzzles etc..
I need really simple platformer controller script. I have looked in example tutorial files, but they're too complicated for me :( Can you write down really normal to understand script for me? If you could, i want there: 1. Moving -left, right (Animation - Running) 2. Jumping - up, falling (Animation - up and fall) 3. Camera on character
That's all. I don't need things like press CTRL to run, particles on jetpack etc... Just a simple & nice script. Thanks much!!
Answer by GamerIDGoesHere · Aug 01, 2012 at 12:42 PM
To change the camera add other stuff like gravity, just place FirstPerson player and delete playerweapons and then make a java script call it Sidescroller then add this code and put the script on your FirstPerson player make sure x,y,z under rotation on Firstperson player are all zero:
var speed = 6.0; var jumpSpeed = 8.0; var gravity = 20.0; private var moveDirection = Vector3.zero; private var grounded : boolean = false; function FixedUpdate() { if (grounded) { // We are grounded, so recalculate movedirection directly from axes moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0); moveDirection = transform.TransformDirection(moveDirection); moveDirection *= speed;
if (Input.GetButton ("Jump")) { moveDirection.y = jumpSpeed; } } // Apply gravity moveDirection.y -= gravity * Time.deltaTime;
// Move the controller var controller : CharacterController = GetComponent(CharacterController); var flags = controller.Move(moveDirection * Time.deltaTime); grounded = (flags & CollisionFlags.CollidedBelow) != 0; } @script RequireComponent(CharacterController)
Your answer
![](https://koobas.hobune.stream/wayback/20220613084159im_/https://answers.unity.com/themes/thub/images/avi.jpg)