Взаимодействия контролера и физ.объектов - Форум Игроделов
Вс, 09 Фев 2025, 18:30 
 
Приветствую Вас Гость Главная | Регистрация | Вход
Новые сообщения · Участники · Правила форума · Поиск · RSS ]
  • Страница 1 из 1
  • 1
Взаимодействия контролера и физ.объектов
MaxUnityDevДата: Ср, 07 Дек 2011, 16:08 | Сообщение # 1
 
Сообщений: 126
Награды: 1
Репутация: 136
Статус: Offline
ГГ теперь может передвигать физ.объекты, не стопорится на них. Удобная штука.

PushBody.js

Code
// this script pushes all rigidbodies that the character touches
var pushPower = 2.0;
function OnControllerColliderHit (hit : ControllerColliderHit)
{
var body : Rigidbody = hit.collider.attachedRigidbody;
// no rigidbody
if (body == null || body.isKinematic)
return;

// We dont want to push objects below us
if (hit.moveDirection.y < -0.3)
return;

// Calculate push direction from move direction,
// we only push objects to the sides never up and down
var pushDir = Vector3 (hit.moveDirection.x, 0, hit.moveDirection.z);

// If you know how fast your character is trying to move,
// then you can also multiply the push velocity by that.

// Apply the push
body.velocity = pushDir * pushPower;
}


Скрипт вешается на сам контроллер игрока.


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 - Чт, 08 Дек 2011, 10:23
 
СообщениеГГ теперь может передвигать физ.объекты, не стопорится на них. Удобная штука.

PushBody.js

Code
// this script pushes all rigidbodies that the character touches
var pushPower = 2.0;
function OnControllerColliderHit (hit : ControllerColliderHit)
{
var body : Rigidbody = hit.collider.attachedRigidbody;
// no rigidbody
if (body == null || body.isKinematic)
return;

// We dont want to push objects below us
if (hit.moveDirection.y < -0.3)
return;

// Calculate push direction from move direction,
// we only push objects to the sides never up and down
var pushDir = Vector3 (hit.moveDirection.x, 0, hit.moveDirection.z);

// If you know how fast your character is trying to move,
// then you can also multiply the push velocity by that.

// Apply the push
body.velocity = pushDir * pushPower;
}


Скрипт вешается на сам контроллер игрока.

Автор - MaxUnityDev
Дата добавления - 07 Дек 2011 в 16:08
valera3132Дата: Ср, 07 Дек 2011, 17:49 | Сообщение # 2
 
Сообщений: 41
Награды: 0
Репутация: 53
Статус: Offline
Я уже сибе довно поставил не хватает только когда он их передвигает чтобы звук был.
И это лучше (pushPower = Random.Range(2.5, 3.5);) happy
Code

function OnControllerColliderHit (hit : ControllerColliderHit) {
  var controller : CharacterController = GetComponent(CharacterController);
  var body : Rigidbody = hit.collider.attachedRigidbody;
  if (hit.collider.attachedRigidbody != null && controller.isGrounded && controller.velocity.magnitude < 18 && controller.velocity.magnitude > 2) {
   pushPower = Random.Range(2.5, 3.5);
   if (body == null || body.isKinematic) {
    return;
   }
   if (hit.moveDirection.y < -0.3) {
    return;
   }
   var pushDir = Vector3 (hit.moveDirection.x, 0, hit.moveDirection.z);
   body.velocity = pushDir * pushPower;
  }
}


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

Сообщение отредактировал valera3132 - Ср, 07 Дек 2011, 17:54
 
СообщениеЯ уже сибе довно поставил не хватает только когда он их передвигает чтобы звук был.
И это лучше (pushPower = Random.Range(2.5, 3.5);) happy
Code

function OnControllerColliderHit (hit : ControllerColliderHit) {
  var controller : CharacterController = GetComponent(CharacterController);
  var body : Rigidbody = hit.collider.attachedRigidbody;
  if (hit.collider.attachedRigidbody != null && controller.isGrounded && controller.velocity.magnitude < 18 && controller.velocity.magnitude > 2) {
   pushPower = Random.Range(2.5, 3.5);
   if (body == null || body.isKinematic) {
    return;
   }
   if (hit.moveDirection.y < -0.3) {
    return;
   }
   var pushDir = Vector3 (hit.moveDirection.x, 0, hit.moveDirection.z);
   body.velocity = pushDir * pushPower;
  }
}

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

Game Creating CommUnity © 2009 - 2025