hey,
yesterday i had a question about SendMessage to another script.
well that works now… but now the problem is how to say that it has to walk forward and backwards.
the problem is almost fixed, but when i push the button it takes a second to walk forward.
and after release it will walk a second further.
another problem is that after i pushed the button once and push it again it will only walk backwards
var speed = 0.0;
var loopspeed = 6.0;
var sprintspeed = 9.0;
var jumpSpeed = 8.0;
var gravity = 20.0;
var turnSpeed = 0.0;
var walkForwardButton : int = 0;
var walkBackwardButton : int = 0;
var zVal : int;
var turnLeftButton : int = 0;
var turnRightButton : int = 0;
private var moveDirection = Vector3.zero;
private var grounded : boolean = false;
function Update ()
{
//print(moveDirection);
}
function FixedUpdate() {
if (grounded) {
// We are grounded, so recalculate movedirection directly from axes
//zVal = Mathf.Max(walkForwardButton, Input.GetAxis("Vertical"));
if (walkForwardButton == 1 || Input.GetAxis ("Vertical") == 1) zVal = 1;
if (walkBackwardButton == -1 || Input.GetAxis ("Vertical") == -1) zVal = -1;
if (walkForwardButton == 0 walkForwardButton Input.GetAxis ("Vertical")==0) zVal = 0;
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, zVal);
//moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
speed = loopspeed;
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
if (Input.GetButton ("Sprint")) {
speed = sprintspeed;
}
}
// 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;
// Check to see if the right mouse button is pressed
if (Input.GetMouseButton(1))
{
// Get the difference in horizontal mouse movement
x = Input.GetAxis("Mouse X") * turnSpeed;
}
// rotate the character based on the x value
transform.Rotate(0, x, 0);
//print (transform.rotation.eulerAngles);
}
function walkForward(val:float)
{
walkForwardButton = val;
}
function walkBackward(val:float)
{
walkBackwardButton = val;
}
function turnLeft(val:float)
{
turnLeftButton = val;
}
function turnRight(val:float)
{
turnRightButton = val;
}
@script RequireComponent(CharacterController)
(there may be some errors in the script because of translation from Dutch to English)
so the questions are:
- how to fix the lagg.
- why does it walk backwards after i pushed the button once before.
(and maybe someone knows how to let my turning work)
Thnx