dostalition, в Joystick механика джойстика прописана,а там есть другой скрипт ,скорее всего тот который ты сказал,вот там поищи где берутся значения переменных из скрипта Joystick.
Сообщение отредактировал Altair - Ср, 21 Май 2014, 19:42
// This script must be attached to a GameObject that has a CharacterController var moveTouchPad : Joystick; var rotateTouchPad : Joystick; // If unassigned, tilt is used
var cameraPivot : Transform; // The transform used for camera rotation
var forwardSpeed : float = 4; var backwardSpeed : float = 1; var sidestepSpeed : float = 1; var jumpSpeed : float = 8; var inAirMultiplier : float = 0.25; // Limiter for ground speed while jumping var rotationSpeed : Vector2 = Vector2( 50, 25 ); // Camera rotation speed for each axis var tiltPositiveYAxis = 0.6; var tiltNegativeYAxis = 0.4; var tiltXAxisMinimum = 0.1;
private var thisTransform : Transform; private var character : CharacterController; private var cameraVelocity : Vector3; private var velocity : Vector3; // Used for continuing momentum while in air private var canJump = true;
static var isGround : boolean;
function Start() { // Cache component lookup at startup instead of doing this every frame thisTransform = GetComponent( Transform ); character = GetComponent( CharacterController );
// Move the character to the correct start position in the level, if one exists var spawn = GameObject.Find( "PlayerSpawn" ); if ( spawn ) thisTransform.position = spawn.transform.position; }
function OnEndGame() { // Disable joystick when the game ends moveTouchPad.Disable();
if ( rotateTouchPad ) rotateTouchPad.Disable();
// Don't allow any more control changes when the game ends this.enabled = false; }
function Update() { var movement = thisTransform.TransformDirection( Vector3( moveTouchPad.position.x, 0, moveTouchPad.position.y ) );
// We only want horizontal movement movement.y = 0; movement.Normalize();
// Apply movement from move joystick var absJoyPos = Vector2( Mathf.Abs( moveTouchPad.position.x ), Mathf.Abs( moveTouchPad.position.y ) ); if ( absJoyPos.y > absJoyPos.x ) { if ( moveTouchPad.position.y > 0 ) movement *= forwardSpeed * absJoyPos.y; else movement *= backwardSpeed * absJoyPos.y; } else movement *= sidestepSpeed * absJoyPos.x;
// Check for jump if ( character.isGrounded ) {
isGround = true;
var jump = false; var touchPad : Joystick; if ( rotateTouchPad ) touchPad = rotateTouchPad; else touchPad = moveTouchPad;
if ( jump ) { // Apply the current movement to launch velocity velocity = character.velocity; velocity.y = jumpSpeed; } } else { // Apply gravity to our velocity to diminish it over time velocity.y += Physics.gravity.y * Time.deltaTime;
// Adjust additional movement while in-air movement.x *= inAirMultiplier; movement.z *= inAirMultiplier; }
movement += velocity; movement += Physics.gravity; movement *= Time.deltaTime;
// Actually move the character character.Move( movement );
if ( character.isGrounded ) // Remove any persistent velocity after landing velocity = Vector3.zero;
// Apply rotation from rotation joystick if ( character.isGrounded ) { var camRotation = Vector2.zero;
if ( rotateTouchPad ) camRotation = rotateTouchPad.position; else { // Use tilt instead // print( iPhoneInput.acceleration ); var acceleration = Input.acceleration; var absTiltX = Mathf.Abs( acceleration.x ); if ( acceleration.z < 0 && acceleration.x < 0 ) { if ( absTiltX >= tiltPositiveYAxis ) camRotation.y = (absTiltX - tiltPositiveYAxis) / (1 - tiltPositiveYAxis); else if ( absTiltX <= tiltNegativeYAxis ) camRotation.y = -( tiltNegativeYAxis - absTiltX) / tiltNegativeYAxis; }
// Rotate the character around world-y using x-axis of joystick thisTransform.Rotate( 0, camRotation.x, 0, Space.World );
// Rotate only the camera with y-axis input cameraPivot.Rotate( -camRotation.y, 0, 0 ); } }
Добавлено (21 Май 2014, 21:29) --------------------------------------------- По сути, как Я понимаю, Мне нужно ставить в условие изменение координат контроллера по Х и Y, и желательно ещё и с зависимостью от скорости изменения, т.к. хочу прилепить анимацию движения камеры при ходьбе и беге .... Я знаю как проверить, изменилась ли позиция относительно статичного объекта, а как с динамикой быть не пойму ....
character.velocity.magnitude-это скорость движения Как проверять движение только по х и z -- да просто..берёшь вектор и от туда забираешь только значения икса и игрика типо movoment.x,movnment.z да и всё