OK so, i know this is stupidly basic and clearly Im doing something stupidly wrong, but even looking at the samples, recreating the rotating cube something hasnt worked and I cant see it
So, new project, add entities and all the bits that come with, add in 1 cube at 0,0,0 set camera so cube is in the middle and start work
I added a convert to entity script with default settings
I made 2 scripts based off the examples, added the cubedata to my cube and set degrees per second to 180
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.Entities;
using Unity.Mathematics;
using UnityEngine;
public class CubeData : MonoBehaviour,IConvertGameObjectToEntity
{
public float DegreesPerSecond;
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
var data = new RotationSpeed_ForEach { RadiansPerSecond = math.radians(DegreesPerSecond) };
dstManager.AddComponentData(entity, data);
}
}
[Serializable]
public struct RotationSpeed_ForEach : IComponentData
{
public float RadiansPerSecond;
}
and
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine;
public class RotatorSystem : ComponentSystem
{
protected override void OnUpdate()
{
Entities.ForEach((ref RotationSpeed_ForEach rotationSpeed, ref Rotation rotation) =>
{
var deltaTime = Time.deltaTime;
rotation.Value = math.mul((rotation.Value), quaternion.AxisAngle(math.up(), rotationSpeed.RadiansPerSecond * deltaTime));
});
}
}
So the million dollar question is why is it not rotating about the centre??
That code looks Ok.
So there is definitely another system affecting your data.
Are you sure there isn’t any other systems that you have done that are touching any of the transform data (LocalToWorld/Translation/Rotation)?
Also you could/should do the above code in a JobComponentSystem where you can take advantage of Jobs and Burst.
Nope it is a 100% blank project as described there are 2 files, and the cube, thats it
thanks for the tip, I was copying the first example in the hellocube example… I am aware there are other ways to do it, I get the ecs principal, just not seeing how I am getting this stupid example wrong
I had a similar looking problem once where the problem was related to parenting, ie. my box was a child of another game object and was not at 0,0,0 in relation to that parent, which made it seem to rotate in weird ways.
Do you only have the cube or is their any parent/chil relationship going on?
I’m new to DOTS, so I’m probably also doing something wrong, but I can’t get it to work at all. I add both of your scripts into a project that already has Entities, Burst, etc. New scene, add a cube at 0,0,0, add the CubeData script to the cube and set rotation to 180. Put a Convert To Entity script on the Cube.
With the default settings for Convert To Entity ‘Convert and Destroy’, the cube disappears. With ‘Convert and Inject’ the cube is there, but does not rotate.
Yep. It works as expected now, rotates around it’s center pivot. I can’t imagine what you are doing that would make it behave like that. I’m using 2019.3.0b5
Well… Im back. and despite previously making 5 different projects trying to work out why it was being wonky… it now works… you know those times where you just want to shout and scream and swear people mess with your stuff? this is me