- Home /
Changeing Walk script to always move
I have this script that I got out of the 2D Lerpz tutorial, --->
var canControl = true;
var spawnPoint : Transform;
class PlatformerControllerMovement { var walkSpeed = 6.0; var runSpeed = 10.0;
var inAirControlAcceleration = 1.0; var gravity = 60.0; var maxFallSpeed = 20.0;
var speedSmoothing = 5.0;
var rotationSmoothing = 10.0; @System.NonSerialized var direction = Vector3.zero;
@System.NonSerialized var verticalSpeed = 0.0;
@System.NonSerialized var speed = 0.0;
@System.NonSerialized var isMoving = false;
@System.NonSerialized var collisionFlags : CollisionFlags;
@System.NonSerialized var velocity : Vector3; @System.NonSerialized var inAirVelocity = Vector3.zero;
@System.NonSerialized var hangTime = 0.0; }
As of right now it works really well, but it isn't exactly what I would like. This script makes my character move every time I press the left/right arrow keys, but I would like it to automatically start moving my character along x axis as soon as my game starts. But I can't for the life of me make sence of this script. Where should I add/change a line of code? Thanks for the help!
-Rov
Answer by hirenkacha · Sep 12, 2012 at 05:22 AM
void Update()
{
moveDirection = new Vector3(1, 0, 0);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= runSpeed;
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
Where controller is the Character controller attached to the player character. let me know if not working. moveDirection is vector3.
Thanks! But I can't seem to get it to work. Do I just replace my old script with this or do I add it in somewhere?
-rov