4️⃣ Unity ECS Tutorial • Player Rotation

preview_player
Показать описание

In this video you'll learn how to implement Unity ECS player rotation. Follow this Unity ECS tutorial series to learn how to create a survival shooter game using Unity's implementation of the Entity-Component-System (ECS) pattern.

Download the project files at

Read the blog post at

My Favorite Unity Assets 💯⤵️

* Disclosure: These are affiliate links, which means I'll receive a commission if you use them to make a purchase.
🎵 Music provided by Argofox:
From The Dust - Stardust
Рекомендации по теме
Комментарии
Автор

Very informative, thanks for making these videos and helping us to understand how ECS will work on a real project. Subscribed!

rickmendez
Автор

You can optimize the PlayerRotationSystem.OnUpdate method. For optimization, you need to save the Camera.main reference in the Init method. Because each call to Camera.main Unity searches for a Сamera component in the game scene.

nikitagoncharuk
Автор

4:07 How da heck did you get that code to function when Unity normally only supports C# up to version 6.0?? Specifically "out var hit" is part of the 7.0 specs and so Unity straight up refuses to run the code as it's not part of the 6.0 language specification.
Edit: Fixed it by declaring the 'hit' var beforehand, but the question remains... I can't find a way, that works, to enable C# 7.0.

Koushakur
Автор

in your Pure or Hybrid video you used a foreach loop on GetEntities<Group>() instead of using the length property and an indexed for loop.
Is there a reason to use one over the others?

Blafaselblubb
Автор

Please clear my confusion, In InputSystem you are feeding data to InputComponent but in RotationSystem you are applying data rather feeding to Quaternion.Value.... Is this a mistake or i am not understating correctly.

sandsoftimer
Автор

I keep geting a error when I try to normalize the quaternion, Any advice?

failingyou
Автор

This tutorial is great. I'm following along but making a 2D equivalent.

pirateskeleton
Автор

Why did you use a different pattern in the RotationSystem. Why not use a Filter and get entities like in the PlayerRotationSystem ?

msfredb
Автор

Why do some developers use var, while others strict type?

Neceros
Автор

what is ComponentArray's doing? why we need it? i cant understand

asdda
Автор

I'm confused about usage of GameObjectEntity script. It only converts MonoBehaviours to ECS components on start, right? So when you destroy or add a component in EntityManager the components in the inspector don't change. Should I sychronize this by destroying the MonoBehaviours when I remove a component? That would be slow as fuck. I'm talking about the Hybrid approach ofc.

chris-pee
Автор

I have followed your tutorial and its great, do you know maybe how to solve this error msg "Rotation quaternions must be unit length."?

RootsterAnon
Автор

For those getting the error:
NullReferenceException: Object reference not set to an instance of an object
PlayerRotationSystem.OnUpdate () (at

You need to tag your scene camera in the Inspector as 'MainCamera'

For the error:
Rotation quaternions must be unit length.


You need to change line 20 in the RotationSystem from: ->

JamesHotchkiss
Автор

Was quaternion.normalized removed from unity?

ronaldojonson
Автор

Seems that GetEntities<Filter> is deprecated and is now Entities.ForEach((ref RotationComponent rotComponent, ref Transform transform) =>

dribbler
Автор

I had 2 problem with this. here are the solutions:
1. Camera.main does not hold a default camera for me.
So I created a variable: "Camera cam;" within the class and used "cam = in the OnUpdate() method. I passed into the Raycast instead of cameraRay to.

Also make the following changes to RotationSystem.cs:
>

lewisdawson
Автор

i remove component form entity, but, system also can get this entity?how to remove a component

jacktang
Автор

How can I use one system for many different entities?
For example, I have CameraSystem which have to move camera depending on charecter position. I cannot filter both of them because concept of pure ECS (wich will be actual when I end my project) dont work this way. Please, help

alexbukin
Автор

Hello Thanks for your tutorial on ECS but My Player is not rotating.

jamalparvez
Автор

dont need a filter line can use Tags with example => {}).run;
an alternative is Enitites.Foreach((ref RotationComponent RotationComponent, in Tranform Transform) => {}).run

Anything in the Foreach will act as a filter or if declared within the WithAll, WithNone peramiters.

with the new ECS method a better way to write out this would be:

public class PlayerRotationSystem : BaseSystem
{
protected override void OnUpdate()
{
var mousePosition = Input.mousePosition;
var cameraRay =
var layerMask = LayerMask.GetMask("Floor");

if (Physics.Raycast(cameraRay, out var hit, 100, layerMask))
{
Entities.Foreach((ref RotationComponent RotationComponent, in Transform Transform) =>
{
var forward = hit.point - transform.position;
var rotation =

RotationComponent.value = new Quanternian( 0, rotation.y, 0, rotation.w).normalized;
}).run()
}
}
}
}

DeathxStrike