mrtk spatial awareness not detect floor - c#

I´m trying at the beginning of my scene an avatar appears and walks at the floor level, but when it appears in some floors and sometimes the avatar only falls all the time.
This is my configuration
I use the default configuration
And I only change the Mesh Display to None
var observer = CoreServices.GetSpatialAwarenessSystemDataProvider<IMixedRealitySpatialAwarenessMeshObserver>();
// Set to not visible
observer.DisplayOption = SpatialAwarenessMeshDisplayOptions.None;
I need to change something else for that would work?
Thanks for the help

Related

Bounding Player to path Unity

Lets say I have a path, could be a line or a curve in Unity and I wanted to allow my player to snap to that path and move along it how would I achieve this. This would look like either a cover system or something similar to how ledges work in Sly Cooper.
While if you want your player's movement to follow a path, there is a technique called WayPoint, which is simply using the build-in navigation system in Unity. There exist so many articles that teaching you how to manually build such a Way Point System, and at the same time, you can get a SimpleWayPoint module from the online assets store.
But if your player is controlled by user, which means the user can control it's movement, let's say pressing 'W' button meaning moving forward while pressing 'S' button meaning moving backwards, and the leftwards and rightwards movement are constrained by the path you defined, unfortunately I didn't find any mature technology which allows you realize this constrains.
However, in the project I accomplished several months ago, I manually handle the coordinates successfully, since I create a city whose streets strictly observe horizontal and vertical grid lines, I can easily controls the target gameobject's X and Y coordinates, by either using the build-in freeze coordinates API or manually reseting the axis values over and over again in the Update() method. So maybe you could using the Update() method to constrain the targets' coordinates by dynamically calculating it's coordinates using the functions representing the path, but I can imagine how complex it would be.
You could try using a navmeshagent, which will be enabled as soon the player would like to use this "auto movement". In your code you can set the destination and in your scene you can create a navmesh, which can be whatever shape you like
You can do it by:
Mark the position from where you want your player NOT to move forward/cross the line.
In your script, mention the position.
LOGIC
if, player position > position marked
then stop the movement,
SYNTAX
private void update(){
if(transform.position.x < -10){
transform.position = new Vector3(-10, transform.position.y, transform.position.z); // Here you can either use `Vector3` or `Vector2` according to your game
}
}

Set a GameObject in front of an image

I'm having trouble setting an image behind a gameobject in unity. I saw a lot of similar questions but none solved my problem. So basically I need to have the image as a child of the object to be able to do what I'm to do. I added an image of my unity view.
You can likely cheat this by using multiple cameras and layers. Set your container GameObject to its one layer (say "GameObjectLayer",) and set your image's GameObject to another layer (say "ImageUILayer".)
Then, create two cameras, and set the following properties:
Camera 1:
Depth = 0
Culling Mask = "GameObjectLayer"
Clear Flags & Background = (whatever you want the main camera background to be)
Camera 2:
Depth = 1
Culling Mask = "ImageUILayer"
Clear Flags = Depth only (this keeps the camera from drawing a background at all)
Each camera renders in turn, starting with the lowest depth and working up from there. Thus, Camera 1 renders everything in the "GameObjectLayer" first; then, Camera 2 renders everything in the "ImageUILayer" over top of that.
It's an extremely useful workaround when you're trying to mix 2D sprites with 3D objects, and it will never give you any flicker or other z-positioning weirdness, because the cameras each render all their layers in turn.
You can use more than two cameras if you need more than two layers of 3D/2D objects; I'm currently using a total of seven cameras with no ill effects.
in your case I suggest you use the(right click and choose)>2D > Sprites and put the sprites behind of the Gameobject

Create objects with ground plane detection only once with Vuforia & Unity

I am trying to create an AR app using Unity & Vuforia. I have a 3D model that needs to be spawned when ground plane is detected.But this needs to happen only once.
The way Vuforia work is, it keeps on spawning objects when new plane is detected. So what i need to do is either detect plane only once or spawn the object only once. As i am new to Unity, i need help doing this. Great if someone could tell me what i need to do to achieve this.
Vuforia has updated.Now There is no DeploymentStageOnce script.Inorder to stop duplicating while we touch, we have to turn off Duplicate Stage in Content Positioning Behaviour (Script)Check the Inspector when we click Plane Finder.
In your app you should have a Plane Finder object somewhere with the following properties set by default
The Plane Finder object has a Behaviour component attached that calls a Position Content method if a plane was found. That method belongs to the Content Positioning Behaviour and it makes an instance (Clone) of your Ground Plane Stage. In order to avoid more than one instance you should import the vuforia Deploy Stage Once script located here: https://library.vuforia.com/articles/Solution/ground-plane-guide.html and you should change the Plane Finder Behaviour as the following:
I struggled a long with it, in short we must disable AnchorInputListenerBehaviour after hit.
I attached a new script on PlaneFinder with this code below:
<!-- language-all: c# -->
public void OnInteractiveHitTest(HitTestResult result)
{
var listenerBehaviour = GetComponent<AnchorInputListenerBehaviour>();
if (listenerBehaviour != null)
{
listenerBehaviour.enabled = false;
}
}
I added event on Plane Finder Behavior
That's all, I hope it will be useful.
For Updated Versions:
go to "Advanced" setting and "On Interactive Hit Test" script -> Select "Off" option for the script.
Most of the answers are correct but kind of obsolete, the correct way to do that is by code.
Create for example a gameObject called GameManager and pass the GroundPlaneStage and a prefab of the object you want to spawn to a script attached to that GameManager for example call it GameManagerScript.cs, and create a small function called spawnObjects which does the following:
public class SceneManagerScript : MonoBehaviour {
public GameObject objPrefab;
public GameObject ground;
private int count = 0;
public void spawnObject() {
Instantiate(objPrefab, new Vector3(count, 0, 0), Quaternion.identity, ground.transform);
count += 2;
}
}
then after that go to the PlaneFinder specifically to the PlaneFinderBehaviour.cs component you will have callbacks for OnInteractiveHitTest and OnAutomaticHitTest, in your case you need the OnAutomativeHitTest, click + and add a new callback (the function spawnObject in code above like in the image below)
also when you instantiate the object of your preference via the prefab don't forget to write the proper position updates to prevent the objects from getting added in the same position
also don't forget to make the GroundPlaneStage the parent of the object and realize that the position you are adding in the Instantiate() function is relative to that parent (GroundPlaneStage which is represented in the code above with the variable ground)
Finally don't forget to uncheck Duplicate Stage from the "Content Positioning Behaviour" component in the Plane Finder as shown in the picture below:
I hope that helps
please try the vuforia website for this problem
Introduction to Ground Plane in Unity

Unity layers not working as I want

So I'm very new to Unity and creating my first 2D game, It will have a player, monsters, platforms and a static background image.
So What I've done is set a 2D sprite as a background image which is on the default layer. I also got a character from the asset store that I just pulled in to the game and set to User layer 8 (player).
The platforms randomly spawn on the map and was not visible through the background at first but when I set the sprite sortingorder to 1 they were visible.
Now for the monsters. They are also from the asset store but inserted into the game via C# code. If I have a the background on screen they are still not visible even if i set the GameObject.layer = 8 for them(to same layer as player). Why? What Is the problem here.
Thanks in advance.
Unity has two types of layers, the ones you're changing are not the ones that determine drawing order, you need to change the SortingLayer and OrderInLayer parameters in the SpriteRenderer component.
https://unity3d.com/learn/tutorials/topics/2d-game-creation/sorting-layers
If you're only using sprites then you can keep all of them in the same SortingLayer and change the OrderInLayer of the background to something like -100.
If you're using 3d models, youre gonna need to manually set the positions of the objects closer or away from the camera (and keep all the sprites on the default SortingLayer).

Character slowly move up the ground using a humanoid animation type in Unity

I have a marine model used in my start project, which will uncontrollably lift off the ground when running. I import the fbx resources, set the animation type as humanoid and configured the avatar by automatically mapping, set up a animator controller that contains only a running animation. Here is about several seconds after playing:
But when using a generic animation type everything works fine. Any suggestions to fix this while still using the avatar system?
UPDATE:
Configure of my 3D model:
This is obviously caused by root motion. What happens is, one loop of your animation takes the character slightly higher. Adding these slight changes up, you get what you're getting. If you don't need root motion (doesn't look like you do), disable it (from the animator component's settings). If you do, either edit the animation to make sure it fits, or disable root motion along the Y-axis (you can do this from the animation's import settings).
In case you don't know what root motion is, it's when the root bone of your model has animations applied. You obviously can't create the entire animation of character running up and down your levels, and until recently (though not MUCH recently) characters where animated in-place, and moved procedurally via code (I know for a fact that Unreal Tournament 3 uses this method, as would any UDK user). Then, people started wondering how they could make their characters move more realistically? I mean, it's not like you walk forward at a constant rate of 4 km/h, you tend to slow down and speed up during different parts of the walk cycle. The same can be applied to video game characters using the technique known as root motion.
With root motion, you actually move the character forward during its animations. This will cause an animation to look really bad in max or maya, since the character will just snap back to its original place after a loop. However, this data is used intelligently in game engines: Rather than use the absolute position the animation yields, you take the velocity out of it between each two frames, and move your character based on that velocity (Unreal engine actually has a really neat acceleration mode for applying root motion, though I'm not really sure how that would be different from velocity mode). This will make your character move forward at the same rate the animation does, and thus you can actually animate the character's movement as well as its limbs and joints. Moreover, since you're using the velocity and not position data from the animation, it will look exactly as you'd expect it to. If you're interested in this technique, take a look at the Mechanim demo pack they have on the asset store. It makes extensive use of root motion to move the character around.
My company was having a similar issue but we still wanted to keep the "Apply Root Motion" toggle checked. When the same animation played on loop, the model stayed in place but if several different animations were played one after another, this caused the model to rotate / shift in position.
The solution for us was ticking these check boxes in the animation settings for each animation. Root Transform Rotation, Root Transform Position (Y), Root Transform Position (XZ).
I had the same issue a few days ago. I found out that the problem was the Apply Root Motion in the Animator script. Make sure it's unchecked.
Tag your player with "Player" in scene
and use this script
float y;
GameObject player;
void Start ()
{
player = GameObject.FindGameObjectWithTag("Player");
y = player.transform.position.y;
}
// Update is called once per frame
void Update ()
{
float diff = player.transform.position.y;
player.transform.Translate ( 0, 0,z - diff);
y = player.transform.position.y;
}
it is little hacky soultion but works!!
note: if you want to use y movement at some point just calculate and add it to diff variable.
For those who couldn't solve this issue with 'bake into pose'.
I tried 'Bake into Pose-Y', but it didn't work.
Meanwhile, in FBX > Animation > Motion, I set 'Root Motion Node' as 'Root Transform'(It was 'None' before), it solved my problem. Unity version is 2020.3.34f1.

Categories

Resources