1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Unity】【ECS】向いている方向へ動かしたい

Last updated at Posted at 2020-11-10

やりたいこと

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を理解するとだいぶ扱いやすくなりますね。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?