Где достать CharacterController.js ??? - Форум Игроделов
Вс, 09 Фев 2025, 18:40 
 
Приветствую Вас Гость Главная | Регистрация | Вход
Новые сообщения · Участники · Правила форума · Поиск · RSS ]
  • Страница 1 из 1
  • 1
Где достать CharacterController.js ???
valera3132Дата: Сб, 17 Дек 2011, 02:22 | Сообщение # 1
 
Сообщений: 41
Награды: 0
Репутация: 53
Статус: Offline
Где взять CharacterController.js ??? biggrin
Понятно что он уже есть а мне его изменить надо. happy


Тут только детский сад.

Сообщение отредактировал valera3132 - Сб, 17 Дек 2011, 02:46
 
СообщениеГде взять CharacterController.js ??? biggrin
Понятно что он уже есть а мне его изменить надо. happy

Автор - valera3132
Дата добавления - 17 Дек 2011 в 02:22
DekterevДата: Сб, 17 Дек 2011, 03:50 | Сообщение # 2
 
Сообщений: 1753
Награды: 16
Репутация: 892
Статус: Offline
Quote (valera3132)
Где взять CharacterController.js ?

Это не скрипт...
Рекомендую внимательно изучить выпадающий список главного меню Unity3d - Component, пункт Physics. smile
Quote (valera3132)
Понятно что он уже есть а мне его изменить надо.

Изменить настройки? Ну так добро пожаловать в окно Inspector, предварительно выделив тот объект к которому он применен... biggrin


Поиск | Правила | Новые сообщения
 
Сообщение
Quote (valera3132)
Где взять CharacterController.js ?

Это не скрипт...
Рекомендую внимательно изучить выпадающий список главного меню Unity3d - Component, пункт Physics. smile
Quote (valera3132)
Понятно что он уже есть а мне его изменить надо.

Изменить настройки? Ну так добро пожаловать в окно Inspector, предварительно выделив тот объект к которому он применен... biggrin

Автор - Dekterev
Дата добавления - 17 Дек 2011 в 03:50
valera3132Дата: Сб, 17 Дек 2011, 04:22 | Сообщение # 3
 
Сообщений: 41
Награды: 0
Репутация: 53
Статус: Offline
хмм а как тогда изменить capsule collider на box collider?

Тут только детский сад.
 
Сообщениехмм а как тогда изменить capsule collider на box collider?

Автор - valera3132
Дата добавления - 17 Дек 2011 в 04:22
Zer0nДата: Сб, 17 Дек 2011, 09:17 | Сообщение # 4
 
Сообщений: 880
Награды: 23
Репутация: 516
Статус: Offline
Quote (valera3132)
хмм а как тогда изменить capsule collider на box collider?

Удалить Capsule Collider, поставить Box Collider. eek


 
Сообщение
Quote (valera3132)
хмм а как тогда изменить capsule collider на box collider?

Удалить Capsule Collider, поставить Box Collider. eek

Автор - Zer0n
Дата добавления - 17 Дек 2011 в 09:17
MaxUnityDevДата: Сб, 17 Дек 2011, 10:34 | Сообщение # 5
 
Сообщений: 126
Награды: 1
Репутация: 136
Статус: Offline
FPSWalkerEnhanced.js

Code
var walkSpeed = 6.0;

var runSpeed = 11.0;

// If true, diagonal speed (when strafing + moving forward or back) can't exceed normal move speed; otherwise it's about 1.4 times faster
var limitDiagonalSpeed = true;

// If checked, the run key toggles between running and walking. Otherwise player runs if the key is held down and walks otherwise
// There must be a button set up in the Input Manager called "Run"
var toggleRun = false;

var jumpSpeed = 8.0;
var gravity = 20.0;

// Units that player can fall before a falling damage function is run. To disable, type "infinity" in the inspector
var fallingDamageThreshold = 10.0;

// If the player ends up on a slope which is at least the Slope Limit as set on the character controller, then he will slide down
var slideWhenOverSlopeLimit = false;

// If checked and the player is on an object tagged "Slide", he will slide down it regardless of the slope limit
var slideOnTaggedObjects = false;

var slideSpeed = 12.0;

// If checked, then the player can change direction while in the air
var airControl = false;

// Small amounts of this results in bumping when walking down slopes, but large amounts results in falling too fast
var antiBumpFactor = .75;

// Player must be grounded for at least this many physics frames before being able to jump again; set to 0 to allow bunny hopping     
var antiBunnyHopFactor = 1;

private var moveDirection = Vector3.zero;
private var grounded = false;
private var controller : CharacterController;
private var myTransform : Transform;
private var speed : float;
private var hit : RaycastHit;
private var fallStartLevel : float;
private var falling = false;
private var slideLimit : float;
private var rayDistance : float;
private var contactPoint : Vector3;
private var playerControl = false;
private var jumpTimer : int;

function Start () {
         controller = GetComponent(CharacterController);
         myTransform = transform;
         speed = walkSpeed;
         rayDistance = controller.height * .5 + controller.radius;
         slideLimit = controller.slopeLimit - .1;
         jumpTimer = antiBunnyHopFactor;
         oldPos = transform.position;
}

function FixedUpdate() {
         var inputX = Input.GetAxis("Horizontal");
         var inputY = Input.GetAxis("Vertical");
         // If both horizontal and vertical are used simultaneously, limit speed (if allowed), so the total doesn't exceed normal move speed
         var inputModifyFactor = (inputX != 0.0 && inputY != 0.0 && limitDiagonalSpeed)? .7071 : 1.0;
             
         if (grounded) {
             var sliding = false;
             // See if surface immediately below should be slid down. We use this normally rather than a ControllerColliderHit point,
             // because that interferes with step climbing amongst other annoyances
             if (Physics.Raycast(myTransform.position, -Vector3.up, hit, rayDistance)) {
                 if (Vector3.Angle(hit.normal, Vector3.up) > slideLimit)
                     sliding = true;
             }
             // However, just raycasting straight down from the center can fail when on steep slopes
             // So if the above raycast didn't catch anything, raycast down from the stored ControllerColliderHit point instead
             else {
                 Physics.Raycast(contactPoint + Vector3.up, -Vector3.up, hit);
                 if (Vector3.Angle(hit.normal, Vector3.up) > slideLimit)
                     sliding = true;
             }

             // If we were falling, and we fell a vertical distance greater than the threshold, run a falling damage routine
             if (falling) {
                 falling = false;
                 if (myTransform.position.y < fallStartLevel - fallingDamageThreshold)
                     FallingDamageAlert (fallStartLevel - myTransform.position.y);
             }
                 
             // If running isn't on a toggle, then use the appropriate speed depending on whether the run button is down
             if (!toggleRun)     
                 speed = Input.GetButton("Run")? runSpeed : walkSpeed;

             // If sliding (and it's allowed), or if we're on an object tagged "Slide", get a vector pointing down the slope we're on
             if ( (sliding && slideWhenOverSlopeLimit) || (slideOnTaggedObjects && hit.collider.tag == "Slide") ) {
                 var hitNormal = hit.normal;
                 moveDirection = Vector3(hitNormal.x, -hitNormal.y, hitNormal.z);
                 Vector3.OrthoNormalize (hitNormal, moveDirection);
                 moveDirection *= slideSpeed;
                 playerControl = false;
             }
             // Otherwise recalculate moveDirection directly from axes, adding a bit of -y to avoid bumping down inclines
             else {
                 moveDirection = Vector3(inputX * inputModifyFactor, -antiBumpFactor, inputY * inputModifyFactor);
                 moveDirection = myTransform.TransformDirection(moveDirection) * speed;
                 playerControl = true;
             }

             // Jump! But only if the jump button has been released and player has been grounded for a given number of frames
             if (!Input.GetButton("Jump"))
                 jumpTimer++;
             else if (jumpTimer >= antiBunnyHopFactor) {
                 moveDirection.y = jumpSpeed;
                 jumpTimer = 0;
             }
         }
         else {
             // If we stepped over a cliff or something, set the height at which we started falling
             if (!falling) {
                 falling = true;
                 fallStartLevel = myTransform.position.y;
             }
                 
             // If air control is allowed, check movement but don't touch the y component
             if (airControl && playerControl) {
                 moveDirection.x = inputX * speed * inputModifyFactor;
                 moveDirection.z = inputY * speed * inputModifyFactor;
                 moveDirection = myTransform.TransformDirection(moveDirection);
             }
         }

         // Apply gravity
         moveDirection.y -= gravity * Time.deltaTime;

         // Move the controller, and set grounded true or false depending on whether we're standing on something
         grounded = (controller.Move(moveDirection * Time.deltaTime) & CollisionFlags.Below) != 0;
}

function Update () {
         // If the run button is set to toggle, then switch between walk/run speed. (We use Update for this...
         // FixedUpdate is a poor place to use GetButtonDown, since it doesn't necessarily run every frame and can miss the event)
         if (toggleRun && grounded && Input.GetButtonDown("Run"))
             speed = (speed == walkSpeed? runSpeed : walkSpeed);
}

// Store point that we're in contact with for use in FixedUpdate if needed
function OnControllerColliderHit (hit : ControllerColliderHit) {
         contactPoint = hit.point;
}

// If falling damage occured, this is the place to do something about it. You can make the player
// have hitpoints and remove some of them based on the distance fallen, add sound effects, etc.
function FallingDamageAlert (fallDistance : float) {
         Debug.Log ("Ouch! Fell " + fallDistance + " units!");       
}

     @script RequireComponent(CharacterController)
      


Чтоб работал Run пропиши в импут название Run и клавишу Left shift

valera3132 - Это тоже пригодится, а вобще это и многое другое есть на офф.сайтеUnity3D на wiki. Вот как то так.


http://www.youtube.com/watch?v=wD6VGTjkK9Q&feature=related

http://www.youtube.com/watch?NR=1&v=lXgX7zvTw0E
http://orbart.free.fr/index.php?Gallery=105 - Созданно на юнити


Сообщение отредактировал MaxUnityDev - Сб, 17 Дек 2011, 14:58
 
СообщениеFPSWalkerEnhanced.js

Code
var walkSpeed = 6.0;

var runSpeed = 11.0;

// If true, diagonal speed (when strafing + moving forward or back) can't exceed normal move speed; otherwise it's about 1.4 times faster
var limitDiagonalSpeed = true;

// If checked, the run key toggles between running and walking. Otherwise player runs if the key is held down and walks otherwise
// There must be a button set up in the Input Manager called "Run"
var toggleRun = false;

var jumpSpeed = 8.0;
var gravity = 20.0;

// Units that player can fall before a falling damage function is run. To disable, type "infinity" in the inspector
var fallingDamageThreshold = 10.0;

// If the player ends up on a slope which is at least the Slope Limit as set on the character controller, then he will slide down
var slideWhenOverSlopeLimit = false;

// If checked and the player is on an object tagged "Slide", he will slide down it regardless of the slope limit
var slideOnTaggedObjects = false;

var slideSpeed = 12.0;

// If checked, then the player can change direction while in the air
var airControl = false;

// Small amounts of this results in bumping when walking down slopes, but large amounts results in falling too fast
var antiBumpFactor = .75;

// Player must be grounded for at least this many physics frames before being able to jump again; set to 0 to allow bunny hopping     
var antiBunnyHopFactor = 1;

private var moveDirection = Vector3.zero;
private var grounded = false;
private var controller : CharacterController;
private var myTransform : Transform;
private var speed : float;
private var hit : RaycastHit;
private var fallStartLevel : float;
private var falling = false;
private var slideLimit : float;
private var rayDistance : float;
private var contactPoint : Vector3;
private var playerControl = false;
private var jumpTimer : int;

function Start () {
         controller = GetComponent(CharacterController);
         myTransform = transform;
         speed = walkSpeed;
         rayDistance = controller.height * .5 + controller.radius;
         slideLimit = controller.slopeLimit - .1;
         jumpTimer = antiBunnyHopFactor;
         oldPos = transform.position;
}

function FixedUpdate() {
         var inputX = Input.GetAxis("Horizontal");
         var inputY = Input.GetAxis("Vertical");
         // If both horizontal and vertical are used simultaneously, limit speed (if allowed), so the total doesn't exceed normal move speed
         var inputModifyFactor = (inputX != 0.0 && inputY != 0.0 && limitDiagonalSpeed)? .7071 : 1.0;
             
         if (grounded) {
             var sliding = false;
             // See if surface immediately below should be slid down. We use this normally rather than a ControllerColliderHit point,
             // because that interferes with step climbing amongst other annoyances
             if (Physics.Raycast(myTransform.position, -Vector3.up, hit, rayDistance)) {
                 if (Vector3.Angle(hit.normal, Vector3.up) > slideLimit)
                     sliding = true;
             }
             // However, just raycasting straight down from the center can fail when on steep slopes
             // So if the above raycast didn't catch anything, raycast down from the stored ControllerColliderHit point instead
             else {
                 Physics.Raycast(contactPoint + Vector3.up, -Vector3.up, hit);
                 if (Vector3.Angle(hit.normal, Vector3.up) > slideLimit)
                     sliding = true;
             }

             // If we were falling, and we fell a vertical distance greater than the threshold, run a falling damage routine
             if (falling) {
                 falling = false;
                 if (myTransform.position.y < fallStartLevel - fallingDamageThreshold)
                     FallingDamageAlert (fallStartLevel - myTransform.position.y);
             }
                 
             // If running isn't on a toggle, then use the appropriate speed depending on whether the run button is down
             if (!toggleRun)     
                 speed = Input.GetButton("Run")? runSpeed : walkSpeed;

             // If sliding (and it's allowed), or if we're on an object tagged "Slide", get a vector pointing down the slope we're on
             if ( (sliding && slideWhenOverSlopeLimit) || (slideOnTaggedObjects && hit.collider.tag == "Slide") ) {
                 var hitNormal = hit.normal;
                 moveDirection = Vector3(hitNormal.x, -hitNormal.y, hitNormal.z);
                 Vector3.OrthoNormalize (hitNormal, moveDirection);
                 moveDirection *= slideSpeed;
                 playerControl = false;
             }
             // Otherwise recalculate moveDirection directly from axes, adding a bit of -y to avoid bumping down inclines
             else {
                 moveDirection = Vector3(inputX * inputModifyFactor, -antiBumpFactor, inputY * inputModifyFactor);
                 moveDirection = myTransform.TransformDirection(moveDirection) * speed;
                 playerControl = true;
             }

             // Jump! But only if the jump button has been released and player has been grounded for a given number of frames
             if (!Input.GetButton("Jump"))
                 jumpTimer++;
             else if (jumpTimer >= antiBunnyHopFactor) {
                 moveDirection.y = jumpSpeed;
                 jumpTimer = 0;
             }
         }
         else {
             // If we stepped over a cliff or something, set the height at which we started falling
             if (!falling) {
                 falling = true;
                 fallStartLevel = myTransform.position.y;
             }
                 
             // If air control is allowed, check movement but don't touch the y component
             if (airControl && playerControl) {
                 moveDirection.x = inputX * speed * inputModifyFactor;
                 moveDirection.z = inputY * speed * inputModifyFactor;
                 moveDirection = myTransform.TransformDirection(moveDirection);
             }
         }

         // Apply gravity
         moveDirection.y -= gravity * Time.deltaTime;

         // Move the controller, and set grounded true or false depending on whether we're standing on something
         grounded = (controller.Move(moveDirection * Time.deltaTime) & CollisionFlags.Below) != 0;
}

function Update () {
         // If the run button is set to toggle, then switch between walk/run speed. (We use Update for this...
         // FixedUpdate is a poor place to use GetButtonDown, since it doesn't necessarily run every frame and can miss the event)
         if (toggleRun && grounded && Input.GetButtonDown("Run"))
             speed = (speed == walkSpeed? runSpeed : walkSpeed);
}

// Store point that we're in contact with for use in FixedUpdate if needed
function OnControllerColliderHit (hit : ControllerColliderHit) {
         contactPoint = hit.point;
}

// If falling damage occured, this is the place to do something about it. You can make the player
// have hitpoints and remove some of them based on the distance fallen, add sound effects, etc.
function FallingDamageAlert (fallDistance : float) {
         Debug.Log ("Ouch! Fell " + fallDistance + " units!");       
}

     @script RequireComponent(CharacterController)
      


Чтоб работал Run пропиши в импут название Run и клавишу Left shift

valera3132 - Это тоже пригодится, а вобще это и многое другое есть на офф.сайтеUnity3D на wiki. Вот как то так.

Автор - MaxUnityDev
Дата добавления - 17 Дек 2011 в 10:34
  • Страница 1 из 1
  • 1
Поиск:
Загрузка...

Game Creating CommUnity © 2009 - 2025