Trailmakers

Trailmakers

26 ratings
「Logic」ブロックの使い方
By ddl
「”Logic” ブロックは何に使うんだろう。どうやって使うんだろう。」という人のためのガイドです。
   
Award
Favorite
Favorited
Unfavorite
1. "Logic" ブロックの種類
どのような "Logic" ブロックがあるか、それぞれ解説します。
1-1. "AND Logic Gate"

"AND Logic Gate” は文字通り AND 演算を行うブロックです。入力が全て "0 以上"、もしくは全て "0 以下" である場合に値を出力します。

主な設定について解説します。
(1) と (2) はキーによる入力を設定するところです。ただし、AND だからといって (1) と (2) のキーを同時に入力した場合に値が出力されるわけではありません。どちらかのキーを入力した場合に、値が出力されます。
そして、基本的には (1) のキーは "1" が、(2) のキーは "-1" が入力されるのですが、他の入力と合わせた場合、少し特殊な動作をするため、[1-4. 入出力表」を見てください。

純粋な AND 回路として使用したいのであれば、(1), (2) は "None" に設定して使用しないほうがよいでしょう。

(3) は出力の大きさです。入力値に対して (3) の値をかけたものが出力されます。つまり、これを "-1" にすれば、出力は反転されます。なお、入力値の大きさは出力に全く関係ありません。

なお、注意すべきは "入力1" と "入力2" は正負が同じで無ければならないことです。つまり、"入力1" が "1" で "入力2” が "-1" の場合、何も出力されません。
1-2. " OR Logic Gate"

"OR Logic Gate” は文字通り OR 演算を行うブロックです。入力いずれかが "0 以上"、もしくは "0 以下" である場合に値を出力します。

設定はすべて "AND Logic Gate" と同じです。

"入力1" と "入力2" は正負が同じで無ければならないのも同じです。

詳細は「1-4. 入出力表」を見てください。
1-3. "XOR Logic Gate"

"XOR Logic Gate” は文字通り OR 演算を行うブロックです。入力の片方のみが "0" 以外の値である場合に値を出力します。

設定はすべて "AND Logic Gate" と同じです。
"入力1" と "入力2" は正負が同じで無ければならないのも同じです。

詳細は「1-4. 入出力表」を見てください。
1-4. 入出力表
入力1
入力2
キー入力
AND
OR
XOR

0
0
-
0
0
0
1
0
-
0
1
1
0
1
-
0
1
1
1
1
-
1
1
0
1
-1
-
0
0
0
-1
-1
-
-1
-1
0

-
-
0
0
0
0
-
-
1
1
1
1
-
-
-1
-1
-1
-1
-
-
両押
0
0
0

1
0
0
0
1
1
1
0
1
0
1
0
1
1
0
0
1
0
1
1
1
1
1
0
1
1
-1
1
1
0
-1
-1
1
-1
-1
0
-1
-1
-1
-1
-1
0
1
-1
1
1
1
0
1
-1
-1
-1
-1
0
1-5. Distance Sensor

"Distance Sensor" は、正面の一定距離内にブロックや壁などのオブジェクトが存在することを検知するセンサーブロックです。
出力が有効であるとき、センサー正面全体が光ります。

主な設定について解説します。

(1) は検知距離です。この設定距離範囲内にオブジェクトが存在するとき出力が有効になります。なお、ブロックの長さ 1 単位は約 0.3m です。

ブロック数
1
2
3
4
...
10
最大非検知(m)
0.3
0.6
0.8
1.1
...
2.6

(2) は出力の大きさです。"Distance Sensor" は範囲内にオブジェクトがあれば必ずこの値を返します。距離によって出力が変わることはありません。

(3) は出力の反転です。範囲内にオブジェクトが存在しない時に値を出力します。

なお、"Piston" は縮んでいる場合でも最大長さ分存在すると判定されます。"Piston" 長さを検知させたい場合は注意してください。
1-6. Speed Sensor

"Speed Sensor" は速度を検知するセンサーブロックです。
正面パネルの枠は速度ゲージになっており、満タンになると有効になります。

主な設定について解説します。
(1) は検知速度です。この設定値以上の速度になると値が出力されます。

(2) は出力の大きさです。いつものごとく、on/off のみであり出力値は常にここに設定した値です。

(3) は出力の反転です。速度が設定値以下である場合に値を出力します。

なお、速度の検出は正面パネルに書いてある矢印の方向に対してのみ測定します。よって、進行速度をトリガーにしたいのにセンサーを進行方向に対し横向きに設定していると、うまく動作しないので注意が必要です。
1-7. Altitude Sensor

"Altitude Sensor” は高度計 (高さセンサー) です。

全面パネルには高度が整数で表示されます。

主な設定について解説します。
(1) は検知高度です。この値以上の高度の時、値を出力します。

(2) は出力の大きさです。値が一定なのもいつも通りです。

(3) は出力反転です。
2. 使用方法
次に、「Logic」ブロックの基本的な使い方について解説します。
2-1. 入出力方法
"Logic" ブロックへの入出力方法を説明します。
といっても、Sensor 系のブロックに入力はないので、入力は "AND", "OR", "XOR" ブロックのみの解説となります。

まず、出力方法から解説します。
"Logic" ブロックを選択して "configure" を開くと他の "Logic" ブロックや操作可能なブロックの上にスライドバーが表示されます。

このスライドバーをクリックすると右にスライドして緑色になります。これで出力先として設定されました。出力先はいくつでも指定可能ですし、受け側も複数の "Logic" ブロックから出力を受けることが可能です。
また、操作可能なブロックを出力先として指定した場合、そのブロック自身の操作設定も有効なままであることに注意してください。逆にうまく使えば、一つの操作ブロックを複数の用途に使用することも可能です。


次いで入力方法ですが、1 章でも解説の通り各ブロックへはキー入力を設定可能ですが、実はそれ以外に入力用の機能は存在しません。よって、入力するには別の "Logic" ブロックから出力を受ける必要があります。

簡単に実例を説明します。LT と RT ボタンの "AND" をライトに出力してみましょう。
すでに説明の通り、"AND Logic Gate” のキー設定に LT と RT ボタンを割り当て同時押しても AND 出力は得られません。

そこで、まず入力用にいずれかの "Logic" ブロックを LT と RT ボタンそれぞれ用に一つずつ用意します。下記では、"AND" と区別できるよう "OR Logic Gate” を使用しています。



次に "AND Logic Gate" を設置し、各 "OR" ブロックから出力設定します。


最後に "Taillight" を設置し、"AND” ブロックから出力設定します。また、"Taillight” の "configure" から "Press on light" にチェックをつけてください。


これで完成です。LT と RT を同時に押下することでライトを on/off できることを確認してください。
3. 使用例
実際にマシンを作成する際の使用例を記載します。気が向いたら増えるかもしれません。
3-1. 初期 ON
変形する乗り物を作るとき、"Piston” は初期位置を "configure" から設定できるので良いですが、"Steering Hinge” など回転する操作ブロックは初期位置を決めることができず不便に思ったこともあるかもしれません。
そこで、ここでは初期 (乗り込む前) から ON 信号を出し、On/Off 切り替えられるようにするための回路を紹介します。

これから作るのは、下記を実現する回路です。
  • 1) 無入力時有効
  • 2) RB ボタンで有効無効切り替え
まず、無入力で On 信号を出すには、"Distance Sensor” ブロックが使用可能です。

"Distance Sensor" のパネル面に他のブロックを隣接させ、あるいはセンサー距離内に設置すれば常に On 信号が出力されます。設置した瞬間、乗り込む前から出力されるので便利です。

ただし、これだけでは On/Off の切り替えができないので、入力用の "Logic" ブロックを設置し、これを "XOR Logic Gate" で接続します。入力用に "OR Logic Gate" ブロックを設置し、"Distance Sensor" と "OR Logic Gate” から "XOR Logic Gate" へ出力を接続してください。
これで完成です。簡単な回路なので特に問題はないと思います。
3-2. 車-空/水操舵モード変更
飛行機や船としても使える車を作る場合、車として走るのに操舵のための羽やエンジンが動くのが邪魔になったり、逆に空中/水中で車のステアリングが邪魔になることがあると思います。
そこで、ここでは車操作モードと空中/水中操作モードを変更するための回路例を紹介します。

これから作るのは、下記を実現する回路です。
  • 1) LB ボタンでモード切替
  • 2) 左スティックの操作をモードによって変更
  • 3) 車のステアリングは無効時操作可能、有効時操作不能
  • 4) 飛行用の操舵 (翼の上げ下げ) は無効時操作不能、有効時操作可能
少し複雑になるので、表などを用いて説明します。

まず、入力用の "Logic" ブロックを設定します。"OR Logic Gate" を三つ (A, B, C) 設置し、それぞれ下表のように設定します。
(1)キー
(1) "Toggle"
(2)キー
(2) "Toggle"
(3)
A
LB
O
None
-
1.0
B
LB
O
None
-
-1.0
C
-
-
1.0






次に飛行機用の操舵回路を作成します。"AND Logic Gate" を二つ (D, E)、"OR Logic Gate" を一つ (F) 設置し、出力先を以下のように設定します。
  • A → D
  • B → E
  • C → D, E
  • D → F
  • E → F
  • F → 操舵ブロック

これで飛行用の操舵回路は完成です。
続いて車用の回路ですが、入力などの "Logic" ブロックは流用できるので、あとは "XOR Logic Gate" を二つ (G, H)、"AND Logic Gate" を一つ (I) 設置し、出力先を以下のように設定します。
  • C → G, H
  • D → G
  • E → H
  • G → I
  • H → I
  • I → 車ステアリングブロック
これで無効時にのみ車の操作ができるようになり、完成です。
一つ一つの動作解説はしないので、実際作成して確認してみてください。

また、テストマシンを「logic-gate test machine」の名で workshop に登録しているので良ければ見てみてください。
3-3. ホバー
"Hover Block” による浮上は、水上で速度が落ちると効果がなくなり水没してしまい安定しません。そこで、これを "Gimbal Jet" により補佐し水上でも安定して浮上できるようにするための回路例を紹介します。

といっても回路自体は大したことありません。
以下のようにホバーの四隅 (必要に応じて数は増やす)、"Hover Block" と同じ高さに "Gimal Jet" と "Altitude Sensor" を並べ、接続するだけです。高さは大体 0.7m に設定すればよいでしょう。また、"Trigger Below" を有効にするのも忘れずに。
なお、上の機体ではわかりやすいよう、出力を "Taillight" にも接続しています。
12 Comments
Cirno(9) 4 Dec, 2020 @ 5:51am 
Heyyy, thanks Kezo!
ItsCody 31 May, 2020 @ 3:33am 
Thank you for the translation Kezo, I'll say for English not being your primary language, luckily, since logic is literally based rather than any culture influenced topic, it translates very well. :)
alvaroping1 27 Feb, 2020 @ 2:57am 
There are some things that are a bit incorrect/incomplete, i made a guide a while ago that's it's complete in english, it can be found here: https://cdn.discordapp.com/attachments/425259359707332608/539060740519100426/Logic_Gates_guide.rtf
Kezo the Cabra 21 Jan, 2020 @ 8:30am 
I think this is all that comes to my head at the moment, I hope it is useful :lunar2019wavingpig:
I'm sorry if my English got things confusing on any point, but it isn't my mother language :( ... also, excuse me for the amount of comments... But it was the only way to post these thoughts since there's a 1000 characters limit for comments...
Kezo the Cabra 21 Jan, 2020 @ 8:29am 
**12th: Output's values can be modified to make engines and thrusters output less power, but they can also be used to modify spinning servo and piston's speed (unless you already marked that pistons cant have their position modified by these values, I think you didn't pointed the speed thing). On rotating servos and hinges, however, logic block's output's value will modify the angle. So, if a rotating servo is set to rotate 180 degrees, and a logic block is outputting 0.5 to it, it will rotate 90 degrees instead; if it is 0.25 output's value, it will rotate 45, and so on... The value set in the rotating servo, or hinge, is considered to be 100% and the output from the logic gate that is feeding it is how much of that % is going to be used. BE CAREFUL, SINCE STEERING HINGES ARE BUGGED CURRENTLY AND THIS WON'T WORK RIGHT ON THEM.
Kezo the Cabra 21 Jan, 2020 @ 8:28am 
**11th: Only one half of the distance sensor is actually detecting things. This can be tested by having two different pistons extending against a sensor on different times. Only one of those pistons will trigger the sensor. Also, the distance sensor can recognize another block to a minimum of 0.125-0.15 meters. -On my testings-. Note that the characters haven't got a hitbox on their legs that is recognized by the sensors, so the detection part of the sensors have to be at least from two to three blocks high from the ground to perceive character's hitbox - wheels can make this height vary since most of them sink into the ground-.

Kezo the Cabra 21 Jan, 2020 @ 8:28am 
**9th: Altitude sensor measures height from "sea level" -all the water on the maps are at the same height which is 0 - to sensor's height. This means that it can be used to hover over the water as well, but also that height detection will vary depending on where the sensor is placed on the build.

**10th: "Delay" feature on logic blocks will start its counting since the first active input it is receiving, even if that input is not enough to activate the block's output. This means, for example, that if having a constant ON sensor outputting 1 to an AND gate called X, and another logic block outputs 1 to X after a few seconds, the AND gate X will output 1 immediatly even if it has a delay activation time of 1 second set, since it counted that from the sensor's outputs and not the second block validating the AND function. This is IMPORTANT! It leads to many errors.
Kezo the Cabra 21 Jan, 2020 @ 8:28am 
**6th: Logic blocks are evaluated 60 times per second, or basically once per frame. This is useful info for super complex logic builds.

**7th: Speed sensors only measure "Linear velocity", so they can behave "weird" on very specific situations.

**8th: Having multiple seats in a build change the way logic gates keybinded inputs are evaluated. For example, if having two seats and one AND gate whose keybinded input is W, the AND gate will only input 1 if both SEATS are inputting W. This can be a headache to people who don't know it, since some circuits would stop working if AND gates to receive inputs from the user.
Kezo the Cabra 21 Jan, 2020 @ 8:28am 
**4th: 1 block distance is exactly 0.25m although the game will round it to be 0.3m in the panel. (So your approximation was right, but not exact).

**5th: OR gates with toggle activated can be used as a latch/memory bit. The only requirement for this to work is that the block that gives input to them must have an active time of "0.02 seconds" (so it will send a pulse instead of a constant output). This requirement is already fulfilled by sensors, since they only send pulses.
Kezo the Cabra 21 Jan, 2020 @ 8:27am 
**2nd: The game rounds the numbers used to the closest eighth decimal, however it will only show a rough approximation of it to the user on the UI. This means that, when typing "0.25", the logic block will use "0.25" as a number, but it will show "0.3" on screen. If "0.0001" is typed, it will be used as "0,0001" for computation purposes, but the game will show "0" on the UI.

**3rd: "Delay...", "active time..." and "time before..." functions are bugged, and they'll only work if at least two of their values are different from zero. However, if only one of those features is wanted to be used, this can be fixed by typing "0.0000001" in the "delay" rectangle. It is a really low number and won't have any noticeable effect on action.