I already have my character walking…
but i want that when the user press Shift arrow key, the speed of movement turn into another value.
Can anyone helpe with some code?
I already have my character walking…
but i want that when the user press Shift arrow key, the speed of movement turn into another value.
Can anyone helpe with some code?
Here is a goofy example in C#. hth
public float WalkAnimSpeed = 1.0f;
if (Input.GetKey(KeyCode.LeftShift))
{
if (Input.GetKey(KeyCode.UpArrow))
{
WalkAnimSpeed = 0.5f;
}
}
// TEMPORARY CODE ADJUST ANIM SPEED
animation["WalkCasual01"].speed = WalkAnimSpeed;
sorry, is not working
Can I see the code that you already have to make your character walk?
sure, it’s a derivate from FPSWalker
var speed = 6.0;
var jumpSpeed = 8.0;
var gravity = 20.0;
var rotateSpeed = 2.0;
private var moveDirection = Vector3.zero;
private var grounded : boolean = false;
function FixedUpdate() {
if (grounded) {
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}
moveDirection.y -= gravity * Time.deltaTime;
var controller : CharacterController = GetComponent(CharacterController);
var flags = controller.Move(moveDirection * Time.deltaTime);
grounded = (flags CollisionFlags.CollidedBelow) != 0;
}
function Update ()
{
var controller : CharacterController = GetComponent(CharacterController);
// Rotate around y - axis
transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
// Move forward / backward
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis ("Vertical");
controller.SimpleMove(forward * curSpeed);
}
@script RequireComponent(CharacterController)
and another to control the animations
function Start ()
{
animation.wrapMode = WrapMode.Loop;
animation["golpear"].wrapMode = WrapMode.Once;
animation["saltar"].wrapMode = WrapMode.Once;
animation["golpear"].layer = 1;
animation["saltar"].layer = 2;
animation.Stop();
}
function Update () {
if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.1)
animation.CrossFade("caminar");
else
animation.CrossFade("standing");
if (Input.GetButtonDown ("Fire1"))
animation.CrossFade("golpear");
if (Input.GetButtonDown ("Jump"))
animation.CrossFade("saltar");
//animation.CrossFadeQueued("cayendo", 0.3, QueueMode.PlayNow);
//animation.CrossFadeQueued("enelaire", 0.3, QueueMode.PlayNow);
}
Can anyone help me please?