Unity 3D Kudan "Place Markerless Object" whenever mesh leaves screen? - kudan

I´m kinda new to Unity 3D and C#. Also i´m not exactly sure how Kudans arbitrary tracking solution works in detail. I´m currently using the Unity Kudan SDK to build a VR positional tracking solution, atleast i will try it. Now my plan is:
Whenever the mesh is leaving the screen, i want to freeze it´s position and find new feature points (the "place markerless object" button is doing this: Find new feature point and place a mesh).
Once it found new feature points (which should be a matter of milliseconds) it defreezes the position of the mesh and use the new feature points to further alter it´s position.
The "find new feature point" idea is necessary because whenever the mesh and the old feature points are leaving the screen, tracking will get very inaccurate.
I already tried this in SampleApp.cs:
bool VRSignal;
public void Start()
{
//Get Bools from "KudanTracker"
GameObject g = GameObject.Find("Kudan Camera");
KudanTracker bScript = g.GetComponent<KudanTracker>();
bool VRSignal = bScript.ArbiTrackIsTracking();
}
public void Update()
{
if(VRSignal == false)
{
// from the floor placer.
Vector3 floorPosition; // The current position in 3D space of the floor
Quaternion floorOrientation; // The current orientation of the floor in 3D space, relative to the device
_kudanTracker.FloorPlaceGetPose(out floorPosition, out floorOrientation); // Gets the position and orientation of the floor and assigns the referenced Vector3 and Quaternion those values
_kudanTracker.ArbiTrackStart(floorPosition, floorOrientation); // Starts markerless tracking based upon the given floor position and orientations
}
}
But now it won´t track properly track anymore, also i´m pretty sure ArbiTrackIsTracking() won´t be the solution for that because it won´t lose tracking when the mesh left the screen.
Do you have any idea to solve this problem?

if I understand well, you want change position of 3d model with trigger as soon as your 3d model disappear of the screen.
And you are right, ArbiTrackIsTracking() remain true even if the 3d model go out the screen because if you move again your screen around the 3d model, the 3d model will be always tracked.
But if you move too much your smartphone logically the tracking stops.
My idea for your issue is to get the position of your 3d model markerless transform driver, because the 3d model moves in function the position and orientation of your smartphone to track.
So you can take the position of the moment where your 3d model begin to be tracked.
Then you give a value who will correspond to the difference of first and last position saved.
And if this difference is get, you stop the tracking with arbitrack stop.
if you have another question you can ask on my twitter account #ModeLolito I could answer faster.
And you can watch my youtube channel to see my works on kudan
https://www.youtube.com/user/modelisationLolito

Related

How to prevent object from flying towards camera when using Ray-cast in unity?

I got an unity project where object is meant to be moving with mouse cursor. The object moves fine, but when the object is still, it starts to float towards the camera that Ray-casts. I would like that the object doesn't float towards camera.
I couldn't find any reason for objects behavior.
I'm quite a novice who's had issues with gameobjects following cursors myself.
But could you try freezing the Y position in the Rigidbody and ensure gravity is unchecked?
More of a workaround if it even works.
Also I believe it's better practice to use rigidbody.position than transform.position. Try this:
public Rigidbody rigidbody;
void Update()
{
rigidbody.position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, -Camera.main.transform.position.z));
}
What is happening here is when you send a ray and you get a hit result using hit.point it gives the exact location of the tris on the object it is hitting. Lets say the object is centered in the world (Vector3.zero). Ray is hitting a tris that is different than the position zero. Just because the object is in x:0y:0z:0 doesnt mean all the tris on the object is located at the same coordinates.
You get the coordinates of the hit.point, they are probably closer than the object center position, therefore the object is updating its center position to the hit.point location. And it does that every frame moving the object closer to camera.
You might want to try sending a ray from screen to world position. You can use custom vector length which would help to keep the object in the same depth you like.
Unity Docs Screen to World

How to fix Blue Screen appearing after GameObject is removed in Unity 2d Project

I have been successfully building and running a Unity 2D game, but started receiving a Blue Screen during one of my operations. Specifically, when I close a popup and remove all of its child Game Objects, the entire Game Screen turns dark blue (the default background color of the main camera). The music for the game still plays and clicks are still registered if you click in the right area (I can still press the back button, just can't see it).
If I remove 1 gameobject, this problem doesn't come up. But once I have to remove 2 game objects, the entire screen turns blue.
This is my function for removing my game object in case it helps, which works perfectly when it comes to actually removing the gameObjects correctly (game objects to be removed are created from prefabs). I think the problem may be with the camera for some reason, but I have no clue as to why it happens on this function.
public void Remove(int index)
{
float toggleWidth = toggle.GetComponent<RectTransform>().sizeDelta.x;
DestroyImmediate(scrollSnap.pagination.transform.GetChild(scrollSnap.NumberOfPanels - 1).gameObject);
scrollSnap.Remove(index);
scrollSnap.pagination.transform.position += new Vector3(toggleWidth / 2f, 0, 0);
}
I don't receive any errors or warnings in the console. Just a blue screen once more than one GameObject is removed
EDIT:
Turns out my main Canvas's planeDistance was being changed from 100 to 3200. I still have no clue as to why this change occurred...but for anyone else having a similar issue with a dark blue screen appearing in the middle or start of their game, then please check the values your canvas and camera in the Inspector. Simply controlling the planeDistance did the trick for me!
Made a new scene next to the sample scene when i started my sprite learning game. Forgot all about that.
When I had to publish it, In the Build Settings, I had the wrong scene selected. So It published an empty scene instead of my game.
I solved it by putting game in 3d mode and realized that the camera is positioned very far from the sprites, just change the z-axis and again go to 2d mode.
Just Move your camera in Z-axis position, it could be too far from object or it is behind the object, you can also check it by 3D mode the check the object position and change it in positive and negative values.

Unity 3D - Dynamically 'slicing' background image

I'm fairly new to Unity and not quite sure how to handle this problem.
I have two images, one has clouds on it (day) and one has stars on it (night). What I want to do is show the clouds in the top of my scene and the stars on the bottom. There is a ground object in the middle of the screen where the player will be walking on, this should be the dividing line between the two images. The ground however is not one straight line but can have height differences.
The "solution" I came up with is to use the ground object(s) to slice the images so it kinda serves as a dividing line. But not sure if this is even possible. Maybe I could do something with 2 different camera's or mask the images somehow.. (Just throwing my own thoughts in here as well) I'll be fumbling around with these things in between and try to keep the topic up to date with what I tried.
I put in an attachment to (hopefully) make it more clear.
Greets,
Lukie
attachment: https://imgur.com/a/lblJXPi
The first solution to my mind was preparing a tileset. If you're not going to design a different section every time. So if you're not going to do a computer design. You can do it yourself by adjusting the size.
You can also dynamically generate the stars with the -y axis of the ground object and the clouds with the + y-axis. You can use instantiate function
Example:
public GameObject clouds;
public GameObject stars;
// Start is called before the first frame update
private void Awake()
{
Instantiate(clouds, new Vector3(this.transform.position.x, this.transform.position.y + 3.625f, this.transform.position.z), Quaternion.identity);
Instantiate(stars, new Vector3(this.transform.position.x, this.transform.position.y - 3.625f, this.transform.position.z), Quaternion.identity);
}
Of course, the background design that you will use here must be sustainable.
Dynamic Background

How to make camera follow a car?

I'm developing car racing game in unity. I put car moving script in bot car and main camera. Camera is following car when moving forward but when car collides with other object and car diverts its position or when I turn car turns also camera but earlier than car so car goes out of scope. I tried to put character controller, tried putting camera in hierarchy still it's not following car smoothly even with smooth follow script. So tell me either way to make camera follow car as we see in other car racing game.
What I recommend for this type of game(where the camera is set to follow a certain object, from place A to place B) is to parent an empty gameobject where you want the camera to end up to the car and another empty gameobject parented to the car for where you want the camera to be looking at.
After this, use the basic camera follow and camera lookat scripts that come with the standar assets and play around with the smoothing factors to suit your game. You have to make sure you imported the scripts package for your project.
OR, if the package is imported, select your camera, go to the component menu, and under "Camera Control" select the "Smooth Follow" script.
If you need the camera to dynamically change position depending on (for example) where the car is on the road, I would consider the same solution but using iTween to alter both gameobjects positions along a predefined path.
More about:
smoothfollow: http://wiki.unity3d.com/index.php/SmoothFollow2
lookat: http://docs.unity3d.com/ScriptReference/Transform.LookAt.html
The setting game camera is really challenging especially when it's come to vehicle camera control because camera movement speed depends upon vehicle speed and it's a little bit difficult to control the camera for a vehicle using the C# script.
I highly recommend you should use unity build in ' Cinemachine Package
' you can install it for free. if you want to learn about cinemachine
and go ahead and check out this video
https://www.youtube.com/watchv=X33t13gOBFw&list=PLOBPWyvPXShNN01VQ1LLPqfCtqeRo95Z1&index=23
and by the way, in this video they are setting cinemachine camera for vehicle
You can
Set the camera as a children of your car (the object you want to
follow)
Write this code taken from here
using UnityEngine;
using System.Collections;
public class CameraController : MonoBehaviour {
public GameObject player; //Public variable to store a reference to the player game object
private Vector3 offset; //Private variable to store the offset distance between the player and camera
// Use this for initialization
void Start ()
{
//Calculate and store the offset value by getting the distance between the player's position and camera's position.
offset = transform.position - player.transform.position;
}
// LateUpdate is called after Update each frame
void LateUpdate ()
{
// Set the position of the camera's transform to be the same as the player's, but offset by the calculated offset distance.
transform.position = player.transform.position + offset;
}
}
One way to do it would be to just set the camera as a child of the car. This will essentially lock the camera and give it the same offsets in position and rotation between the car and the camera. You could also try Cinemachine, which is a package that has a lot of useful features that will basically do the same thing while also giving you some more features that you may want. There's quite a bit of documentation on it if you really want to get into it:
https://unity.com/unity/features/editor/art-and-design/cinemachine
Just add the camera to the car as a child object

Not able to run unity 3d app properly

I have just started to learn Unity 3D. I am using this as first lesson. I created a terrain, added texture, plants and grasses, added first person controller and directional lighting. When I press play, the scene automatically starts moving along Y direction. I want the scene to move only when i give input using keyboard or mouse. How to achieve this ?
The first person controller has to be placed above the terrain completely. After doing this I get the desired effect.

Resources