B1 中級 英國腔 2117 分類 收藏
開始影片後,點擊或框選字幕可以立即查詢單字
字庫載入中…
回報字幕錯誤
In order to make a collider into a
trigger we simply check the
'Is Trigger' checkbox on the component
settings in the inspector.
When a collider is a trigger things will
no longer bump into it. Instead they will
pass through it and this can be detected
via code.
Similar to normal colliders,
events are called when other colliders
are overlapping with the trigger collider.
In this example we have a box collider
with Is Trigger checked
and a falling 'prop samoflange' ball object.
This object enters the trigger,
stays as it rolls forward and then exits.
To check these events we attach a script
to the trigger, which is registering
OnTriggerEnter and logging to the console
and likewise OnTriggerStay
and OnTriggerExit.
So if we pause the game
and step through one frame at a time,
looking at the console will show that the
object enters the trigger
stays for a number of frames
and eventually exits the trigger.
In the same way as standard collisions,
one of the two objects must have a rigidbody.
It's standard practice to make sure that your trigger
colliders are static objects,
meaning they will not be moved by the
physics engine. So usually you will make
a trigger and then pass a rigidbody
through it. This example is no different.
We're passing our rigidbody object
through the trigger zone and detecting
when something enters that trigger.
So the intention with the trigger collider,
also known as a trigger zone,
is that you can call code without the
objects in your game physically colliding.
So for example, with our hoverpad,
we can add a force to our samoflange ball
to give the effect of it hovering
so long as it stays within the trigger zone.
For example, we could address the object
that's currently staying within the trigger
because the object that's staying
is saved in a variable called 'other'
of type Collider. We could then address
the rigidbody and add a force
in the direction of Vector3.up,
a shortcut for 'up' in world coordinates.
We could then multiply by a number
which we'll save as a variable.
And we'll finish out the AddForce
by choosing acceleration as the mode.
Now we'll move our object over the hoverpad
and we'll use Freeze Position to keep it
in the same place in X and Z.
Allowing the force of Y to create
the hovering effect.
And now if I press play, as you can see
as long as it stays within that area
it creates the effect of hovering without
having to interact without any part
of the geometry.
提示:點選文章或是影片下面的字幕單字,可以直接快速翻譯喔!

載入中…

碰撞器的触发 - Unity 官方教程 (Colliders as Triggers - Unity Official Tutorials)

2117 分類 收藏
朱瑛 發佈於 2014 年 5 月 2 日
看更多推薦影片
  1. 1. 單字查詢

    在字幕上選取單字即可即時查詢單字喔!

  2. 2. 單句重複播放

    可重複聽取一句單句,加強聽力!

  3. 3. 使用快速鍵

    使用影片快速鍵,讓學習更有效率!

  4. 4. 關閉語言字幕

    進階版練習可關閉字幕純聽英文哦!

  5. 5. 內嵌播放器

    可以將英文字幕學習播放器內嵌到部落格等地方喔

  6. 6. 展開播放器

    可隱藏右方全文及字典欄位,觀看影片更舒適!

  1. 英文聽力測驗

    挑戰字幕英文聽力測驗!

  1. 點擊展開筆記本讓你看的更舒服

  1. UrbanDictionary 俚語字典整合查詢。一般字典查詢不到你滿意的解譯,不妨使用「俚語字典」,或許會讓你有滿意的答案喔