やりたいこと
Unity ECS でオブジェクトを描画し、個別に向いている方向へ進ませたい
問題・試したこと
transform.Translate(Vector3.forward * Time.deltaTime);
は使えません。どうしたものか。
解決方法
translation.Value += LocalToWorld.Up * deltaTime * <速度>;
で解決しました。
コード例
MoveSystem.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Entities;
using Unity.Transforms;
public class MoveSystem : ComponentSystem
{
protected override void OnUpdate(){
var dt = Time.deltaTime;
Entities.ForEach((ref Translation translation, ref Speed speed, ref Rotation rotat, ref LocalToWorld ltw) => {
speed.velocity += dt * speed.accel;//AccelをもとにVelocityに反映
translation.Value += ltw.Up * dt * speed.velocity;
//頭方向にVelocityずつtranslationを更新
});
}
}
LocalToWorldを理解するとだいぶ扱いやすくなりますね。