- Home /
Question by
ProXenT · Nov 30, 2012 at 09:50 AM ·
movementcharactercontroller
help pls beginner, keyboard script
I everyone, i'm making like a Multiplayer PacMan for fun.
And i need to know if this is possible to control one PacMan with ''Arrows key'' and the other one with ''WASD key''..
plz help me, you can take a look on my script (JavaScript) :
var speed = 13;
var jumpSpeed = 8.0;
var gravity = 20.0;
private var moveDirection = Vector3.zero;
private var grounded : boolean = false;
function FixedUpdate() {
if (grounded) {
moveDirection = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}
//For Gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move character
var controller : CharacterController = GetComponent(CharacterController);
var flags = controller.Move(moveDirection * Time.deltaTime);
grounded = (flags & CollisionFlags.CollidedBelow) != 0;
}
@script RequireComponent(CharacterController)
Comment
Best Answer
Answer by DeveshPandey · Nov 30, 2012 at 10:48 AM
Put this script on any object which is in the scene(camera etc).
var speed : float = 6.0; var jumpSpeed : float = 8.0; var gravity : float = 20.0;
private var moveDirection : Vector3 = Vector3.zero;
function Update() {
var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded) {
// We are grounded, so recalculate
// move direction directly from axes
moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,
Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
controller.Move(moveDirection * Time.deltaTime);
}
Answer by ProXenT · Nov 30, 2012 at 08:57 PM
I'm a noob in programation, i don't know anything of what o have to do.. i get my script (as you see on top) but i dont know what i have to change...