diff --git a/Unity/DifferentialDrive.cs b/Unity/DifferentialDrive.cs index 01dcbb5..e8f8858 100644 --- a/Unity/DifferentialDrive.cs +++ b/Unity/DifferentialDrive.cs @@ -22,12 +22,14 @@ namespace RoboidControl.Unity { /// If this is not available, a default representation is created. public static DifferentialDrive Create(RoboidControl.DifferentialDrive coreDrive) { DifferentialDrive differentialDrive; + Rigidbody rb = null; GameObject prefab = (GameObject)Resources.Load("DifferentialDrive"); if (prefab != null) { // Use resource prefab when available GameObject gameObj = Instantiate(prefab); differentialDrive = gameObj.GetComponent(); differentialDrive.Init(coreDrive); + rb = gameObj.GetComponent(); } else { // Default implementation @@ -35,10 +37,14 @@ namespace RoboidControl.Unity { differentialDrive = gameObj.AddComponent(); differentialDrive.Init(coreDrive); - Rigidbody rb = gameObj.AddComponent(); + rb = gameObj.AddComponent(); rb.isKinematic = false; rb.mass = 0.1f; } + if (coreDrive.isRemote) { + if (rb != null) + rb.isKinematic = true; + } return differentialDrive; } diff --git a/src/Participants/ParticipantUDP.cs b/src/Participants/ParticipantUDP.cs index 76f6119..297ffc4 100644 --- a/src/Participants/ParticipantUDP.cs +++ b/src/Participants/ParticipantUDP.cs @@ -463,8 +463,18 @@ namespace RoboidControl { this.updateQueue.Enqueue(e); Console.WriteLine("Added Participant"); } + Thing thing = owner.Get(msg.networkId, msg.thingId); - thing ??= ProcessNewThing(owner, msg); + if (sender.networkId != owner.networkId) { + // Sender forwarded this thing msg + // So this is a remote thing + thing ??= ProcessNewThing(owner, msg, true); + } + else { + // Sender is the owner of the thing + // So this is a simulated thing + thing ??= ProcessNewThing(owner, msg, false); + } if (msg.parentId != 0) { thing.parent = owner.Get(msg.networkId, msg.parentId); @@ -479,7 +489,7 @@ namespace RoboidControl { ForwardMessage(sender, msg); } - protected virtual Thing ProcessNewThing(Participant owner, ThingMsg msg) { + protected virtual Thing ProcessNewThing(Participant owner, ThingMsg msg, bool isRemote) { Console.WriteLine("--- New Thing"); Thing newThing = msg.thingType switch { Thing.Type.TouchSensor => new TouchSensor(owner.root), @@ -488,6 +498,7 @@ namespace RoboidControl { }; newThing.id = msg.thingId; newThing.type = msg.thingType; + newThing.isRemote = isRemote; return newThing; } diff --git a/src/Thing.cs b/src/Thing.cs index 36720db..56e3f16 100644 --- a/src/Thing.cs +++ b/src/Thing.cs @@ -136,6 +136,8 @@ namespace RoboidControl { /// This can be either a \ref RoboidControl::Thing::Type "Thing.Type" or a byte value for custom types. public byte type = Type.Undetermined; + public bool isRemote = false; + /// /// The participant owning this thing ///