If you use the latest version of AR foundation (I had to manually edit Packages/manifest.json to get it) and also have an iphone with an A12 processor or later, you can have body tracking.
You can track 3d or 2d human bodies.
I am interested in the 2d tracking.
In Unity's demo they are using this line of code to get the human body data
var joints = m_HumanBodyManager.GetHumanBodyPose2DJoints(Allocator.Temp);
Which seems to only return info for one body even if the phone can see 2 or more.
I am wondering if tracking multiple bodies is possible, some functions of the humanBodyManager class seem to hint at this being possible. eg.
This function
OnTrackablesChanged(List<ARHumanBody>, List<ARHumanBody>, List<ARHumanBody>)
List<ARHumanBody> added
The list of human bodies added to the set of trackables.
List<ARHumanBody> updated
The list of human bodies updated in the set of trackables.
List<ARHumanBody> removed
The list of human bodies removed to the set of trackables.
and this event
public event Action<ARHumanBodiesChangedEventArgs> humanBodiesChanged
The event that is fired when a change to the detected human bodies is reported.
That function is protected, and I have tried subscribing to that event but it doesnt ever seem to be called. Its also very weird as its an event which wants to call functions which return an action that takes ARHumanBodiesChangedEventArgs as a paramater... I dunno why anyone would ever write a thing like that tbh.
Anyway writing visual debug code and then building to iOS to test all these semi documented classes is a massive pain. If someone could just let me know if multiple body tracking is even possible with ar foundation that would help me a lot. Thanks!
Related
I am new to Unity. I have been working on a simulation , where it was using MapSDK from Google. Now , we were asked to completely move out of 'Google Maps SDK for Unity' and use another asset from the Unity asset store called "world composer". So instead of Google MapSDK generating building and all, using the "world composer" , I just import the satellite ground image of a location like any game objects. I am trying to remove all lines of code in the present simulation that uses Google Maps SDK.
The simulation has the following individual c# scripts.
ProtectedZonesManager.cs //Generates a bubble like structure called protectd zones
AI_DroneManager.cs //Generates a swarm of drones which orbits around the protected zones
and few other scripts
3. AADManagers.cs is a centralized scripts managing all the scripts above
I come across this line which uses delegates in AADManagers.cs
"DynamicMapsService.MapsService.Events.MapEvents. Loaded.RemoveListener(mapsLoadedAction);"
as below.
I am trying to understand what it means or does and how to replace it , so it doesn't have any association with MapsSDK (or DynamicMapsService). The new asset doesn't have any events nor does it need listeners(I think), as it is just a game object(with image). Any idea on that would be very helpful. Thank you
UnityAction<MapLoadedArgs> mapLoadedAction = null;
mapLoadedAction = new UnityAction<MapLoadedArgs>(delegate (MapLoadedArgs args)
{
StartActorManagers();
DynamicMapsService.MapsService.Events.MapEvents.Loaded.RemoveListener(mapLoadedAction);
});
DynamicMapsService.MapsService.Events.MapEvents.Loaded.AddListener(mapLoadedAction);
}
/// <summary>
/// Starts all actor managers scripts
/// </summary>
private void StartActorManagers()
{
ProtectedZonesManager.PostMapLoadStart();
AI_DroneManager.PostMapLoadStart();
//MissileLauncherManager.PostMapLoadStart();
}
What does it do / mean
well there are the two lines
DynamicMapsService.MapsService.Events.MapEvents.Loaded.RemoveListener(mapLoadedAction);
and
DynamicMapsService.MapsService.Events.MapEvents.Loaded.AddListener(mapLoadedAction);
Basically what actually happens is, the second one is executed first!
You add a listener to the event called DynamicMapsService.MapsService.Events.MapEvents.Loaded. So once this event is invoked (by the MapsSDK apparently) you execute everything placed inside the mapLoadedAction which is
StartActorManagers();
DynamicMapsService.MapsService.Events.MapEvents.Loaded.RemoveListener(mapLoadedAction);
were you remove that very same listener so it is only executed ONCE and if the same event is invoked again later (for whatever reason) you ignore that later invocation.
Now how do remove/replace it
This depends very much on how exactly your new library works. If it has events as well you would probably do something similar but there is no way for us to tell without knowing the API of hat new asset you want to use ;)
I am facing some issues with working with the "new" Unity input system. I am working on an FPS prototype, where the player can pick up different guns with different windup times. I do not want to keep track of how long the player has held the shoot key, as the Hold interaction can do that by itself.
Looking around Unity documentation, MS Intellisense suggestions, and Stackoverflow, I have not seen a single instance of something around the lines of "Override interactions of InputAction". It is simply something not being talked about. Should I take that as a red flag for what I am doing is wrong? Probably.
I can see the interactions field for an InputAction, but it is marked with the readonly keyword. There is no internal setter for it either. Otherwise, the solution would be trivial, though unusual to the Unity™ way.
float duration = 0.04f;
controls.Main.Shoot.interactions = $"Hold(duration={duration})";
// Error: "Interactions" is readonly
Is there really not a way to edit the interactions for an InputAction during runtime with code?
So I've been researching how to make certain players (both offline and online for consoles and PC) invisible to other players in Unity for both 2D and 3D. I know having a separate layer for each player and their camera isn't efficient or effective and I was looking for something better. After days of research I finally found these:
Camera-onPreRender, Camera-onPreCull, and Making GameObejcts dynamically invisible
But I'm still very confused.
Are the public void MyPreRender(Camera cam) & public void MyPreCull(Camera cam) delegates or something and the Enable/Disable just changing the value of camera to exclude game objects listed in the function? If so shouldn't they be labeled as a delegate to work? If not how does this function change the value of what game objects should or shouldn't be culled/rendered?
Also would this work well for what I'm doing with little hit on performance and frame rate? The other person said it did but does it really? Is there a better and faster way?
Yes, MyPreRender and MyPreCull are delegates (or rather, a method that matches the signature of a defined delegate elsewhere). Specifically, they are Event Handler methods.
When the camera does a Render (or Cull) task, it first invokes all methods that have been subscribed to the PreRender (or PreCull) events (through the use of the += to tell the other system about your handler method).
You can find out more about events from this Unity tutorial.
I am working on Unity for a month. I am new on Unity and C#, before Unity I worked other game engines. Whatever I am working on infinite run game, I wrote random road generator. Road generator is working well but I have problem about updating road. I can update road manualy like this. How can I update it automaticly?
void Update()
{
if(Input.GetKeyDown(KeyCode.A)) UpdateRoad();
}
My UpdateRoad method adding road like this(I am using object pooling).
I want to update after Link Road, OnExitTrigger or something I dont know. How can I do it?
You would need to implement Object Pooling.
I would suggest making your Design of Objects first so you can test. Or if not use, the stock Blocks Primitive of Unity3D as your Prefabs. I hope you already know prefabs. It is a major key for making infinite runner. Actually a main core for making any kinds of game.
Prefabs is an Object File where you can Instantiate it in a location. So lets say you will generate a Flat walkable, then Generate a Pit. You would probably want to stack them together.
Now Generating them is easy. You would not like to go in an Update? Approach because most likely you're not going to update, but you're going to further stack what is going on ahead, based on your game logic.
To further Understand this, Unity3D already made a project or Fully Detailed tutorial. It maybe made in 2D but it is going to be the same, if you're going to change the Collider2D to Collider <- this is important in your case.
https://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/infinite-runner
Update
You would need to create an Object, that is invisible. Meaning a Trigger.
Then on Trigger call your method UpdateRoad();
https://unity3d.com/learn/tutorials/modules/beginner/physics/colliders-as-triggers
Detailed Videos about Trigger.
If I understood your needs correctly, you could create Empty Object name it SpawnPoint, set position for Spawn Point as you need (out of the camera view) and then Instanciate random prefabs of road. Concerning On TriggerExit - it could be used to destroy "old piece of road". But to have it working properly, dont forget to set collider and rigitbody to your objects. Dont add collider2D or Rigitbody2d, add and use Box Collider and Rigitbody components
I'm writing a particle system and have a hierarchy of one emitter containing many particles.
Particles fire an event on collision with the world:
public event EventHandler<HitWrapperArguments> onHitCallback;
I am in the process of having the emitter subscribe to each particle so it can fire an event when any particle collides:
public event EventHandler<ParticleHitWrapperArguments> onParticleHitCallback;
My question is:
Should my ParticleHitWrapperArguments contain the HitWrapperArguments, or should I unpack HitWrapperArguments and put the collision information directly into ParticleHitWrapperArguments?
Personally it doesn't matter too much to me, but I would go for 2.
It just looks cleaner and I think it will be easier in use. It does need additional coding which could result in extra mistakes, but I wouldn't worry to much about it.
There is no correct answer but I would say use option 1.
It is less work and thus less error prone, and it will leave you with a structure resembling the order of creation which will make it easier to debug (think inner exceptions). If you change your structure you would have to perform minimal changes on the wrapping args class, just one example of how it is better design.
If you have to do any processing on the arguments at this stage however, then of course perform these operations and store the new results in your new args object.