Adding Physics Forces

Проверено с версией:: 4.1

-

Сложность: Базовая

How to use the AddForce function to move a physics (rigidbody) object.

Adding Physics Forces

Базовая Physics

Транскрипты

HoverPad

Code snippet

using UnityEngine;
using System.Collections;

public class HoverPad : MonoBehaviour
{
    public float hoverForce;

    
    void OnTriggerStay (Collider other)
    {
        other.rigidbody.AddForce(Vector3.up * hoverForce, ForceMode.Acceleration);
    }
}
#pragma strict

public var hoverForce : float;


function OnTriggerStay (other : Collider)
{
    other.rigidbody.AddForce(Vector3.up * hoverForce, ForceMode.Acceleration);
}
import UnityEngine
import System.Collections


public class HoverPad(MonoBehaviour):

    public hoverForce as single

    
    
    private def OnTriggerStay(other as Collider):
        other.rigidbody.AddForce((Vector3.up * hoverForce), ForceMode.Acceleration)

Связанные обучающие материалы

Дополнительная документация

  • AddForce (Справка по скриптам)
  • ForceMode (Справка по скриптам)
  • Rigidbody (Справка по скриптам)