乗ってキャラクターが運ばれるブロックの作り方を2種類ご紹介します。
BodyPosition – 指定の位置まで移動
BodyVelocity – 一定の速度で移動
共通内容
PartにScriptとBodyAngularVelocityをインサート
![](https://static.selegee.com/wp-content/uploads/20210511164338/image-4.png)
BodyAngularVelocityのプロパティを変更
BodyAngularVelocityのプロパティを変更します。
変更しないとブロックに乗った時に回転してしまいます。
AngularVelocity:0.0.0
MaxTorgue: inf,inf,inf
![](https://static.selegee.com/wp-content/uploads/20210509162310/image.png)
Partのプロパティを変更(任意)
動かしたいブロックPartが別の物体に衝突する場合は以下の値を設定しておくと安定します。
Dencity:100
Elacity:1
ElacityWeight:100
![](https://static.selegee.com/wp-content/uploads/20210509172029/image-2.png)
あとはAnchoredのチェックはないことを確認しておきましょう
![](https://static.selegee.com/wp-content/uploads/20210509172232/image-3.png)
BodyPositionを利用する場合
特定の位置まで移動したい場合はBodyPositionを利用します。ただし、速度が一定ではなく最初が速く、目的地に近づくにつれ、徐々に減速します。
BodyPositionをインサート
![](https://static.selegee.com/wp-content/uploads/20210511164601/image-5.png)
BodyPositionのプロパティを変更
BodyPositionのプロパティを変更します。
MaxForceが低いと空中に浮いてくれません。
MaxForce: inf,inf,inf
Velocity: 0,0,0
P(Power)の値で速度を調整します。
![](https://static.selegee.com/wp-content/uploads/20210511165009/image-6.png)
Scriptを記載
local rootPart = script.Parent
local rootPosition = rootPart.Position
local bodyPosition = rootPart.BodyPosition
local direction1 = Vector3.new(0, 30, 0)
local movingTime = 4
while true do
bodyPosition.Position = rootPosition + direction1
wait(movingTime)
bodyPosition.Position = rootPosition
wait(movingTime)
end
BodyVelocityを利用する場合
一定の速度で移動させたい場合はBodyVelocityを利用します。ただし、物体やプレイヤーに衝突すると軌道がずれる可能性があります。
BodyVelocityをインサート
動かしたいPartにBodyVelocity
をインサートします。
![](https://static.selegee.com/wp-content/uploads/20210509161723/0d40a5e4a645fc6b96e767d64ac0878e-2.png)
BodyVelocityのプロパティを変更
BodyVelocityのプロパティを変更します。
MaxForceが低いと空中に浮いてくれません。
MaxForce: inf,inf,inf
Velocity: 0,0,0
![](https://static.selegee.com/wp-content/uploads/20210509162921/image-1.png)
Scriptを記載
Script:
local part = script.Parent
local bodyVelocity = part.BodyVelocity
local direction1 = Vector3.new(-10, 0, 0)
local direction2 = Vector3.new(10, 0, 0)
local neutral = Vector3.new(0, 0, 0)
local stoppingTime = 1
local movingTime = 3
while true do
bodyVelocity.Velocity = direction1
wait(movingTime)
bodyVelocity.Velocity = neutral
wait(stoppingTime)
bodyVelocity.Velocity = direction2
wait(movingTime)
bodyVelocity.Velocity = neutral
wait(stoppingTime)
end
参考
詳しくは公式ドキュメントを参考。
https://developer.roblox.com/en-us/articles/BodyMover