====== lerpを使ったAからB地点への移動 ====== lerpを使用してA地点からB地点までN秒かけてなめらかに移動するサンプルです。\\ 今回はアイテムをonUseした場所をA地点としています。4秒かけてB地点(0,1,0)へと移動します。 === サンプルデータ === https://virtualcast.jp/products/027128433fc0305d1131027f25a3ef30d56592d7cc6aaafbfe588c236a3242fd === Unitypackage === {{ :vci:sample:sample_advanced:tutorial_lerp.unitypackage |}} ===== VCIスクリプト ===== local framevalue = vci.me.Time.TotalSeconds local framestart = 0 local sub = vci.assets.GetTransform("Sub") local pointA = Vector3.__new(0,1,0)--A地点 local pointB = Vector3.__new(0,1,0)--B地点 local pointnow =Vector3.zero local moveflag = 0 local distance = 0.01 --この距離以下になったら停止 function updateAll() if moveflag==1 then framevalue = (vci.me.Time.TotalSeconds-framestart)/4 --この場合は4秒かけて移動 --A地点からB地点まで補間してN秒間で移動 pointnow = Vector3.Lerp(pointA,pointB,framevalue) sub.SetLocalPosition(pointnow) if Vector3.Magnitude(sub.GetLocalPosition()-pointB)