How I fix my character into center of camera with unity 3d - unity3d

I need a solution for my problem, please.
I make a character in unity 3d base on AR, the problem is when I build the project in my android phone I can found the character or I should to turn a camera for search where is he.
I need to make this object into the center of my camera how can I do this, please ...

The question isn't the clearest, but I suggest attaching the camera to the gameobject you want to see in the editor.
This link is to a unity tutorial.
https://unity3d.com/learn/tutorials/projects/2d-ufo-tutorial/following-player-camera

Just re-read your question, AR skimed over that at first ... so you dont want to move the camera rather you want to move the object.
To find the middle of the screen in world space is what you asking for.
Camera.current.ViewportToWorldPoint(new Vector3(0.5f,0.5f, 100));
Use your camera to find a point in the world that is in the middle of your view. You have several options, ViewportToWorldPoint for example as shown above. ViewPort calls 0.5,0.5 the middle of the screen, Z is the distance from the Camera origin point.
You could alternativly cast a ray from your camera center screen and find a point on the ground to put your character at ... would need to know more about your wourld set up to help further.
My old answer is how to move a camera ... I will leave it case its useful to you.
[Edit Old Answer]
The other answer will work and is nice and light but has its limitations as your project advances.
I recomend Cinemachine for camera work, in this case a simple Cinemachine virtual camera setting its 'Look At' and optionaly its 'Follow' is what you want.
https://unity3d.com/learn/tutorials/topics/animation/using-cinemachine-getting-started
Cinemachine tutorail above. in short, Cinemachine works with the concept of 'virtual cameras' these are just light easy to use behvaiours that discribe how to 'frame' a shot e.g. what to look at, how to move, etc.
You real camera will get a Cinemachine 'brain' which simply listens to these virtual cameras and sorts out what to do to the real camera to make it happen. Getting to terms with this system will greatly improve your camera work and masivly simplify it.
Things like simply attaching the camera to the player object and similar work but have big limitations that end up biting you in the backside eventually.
Alternativly you can write a script to transform the camera based on your own custom logic the draw back here is the 'ball of code' problem ... that is at first the logic is simple but as you want more and more specific shots framed up it gets to being a spegettie monster quickly.

Related

Cinemachine: Lock rotation and smooth movement

I'm trying to figure out Cinemachine to create some kind of Top view perspective. I managed to find the setting to make sure the camera keeps it's rotation, and follows the player. My issue now is that little extra movement that happens when the player is moving. Is there a way for me to get rid of it, so that my camera stays still?
What I have
Camera Settings
What I'm trying to achieve
Edit:
Edit after comment
Camera settings
You can set Body type to transposer and Binding Mode to world space:
Have you tried to change the aim setting to Do Nothing? If you leave it to Hard look at it will always keep your player at the center of the camera.
You can read the documentation here:
https://docs.unity3d.com/Packages/com.unity.cinemachine#2.6/manual/CinemachineVirtualCameraAim.html

How to override physical marker in vuforia AR Camera in runtime?

How can I override the physical marker in unity to just make the physical marker invisible in camera while detecting any object.
Like in this video:
https://m.youtube.com/watch?v=R_F1LvK5gCk
And many other videos.
This maybe isn't the correct answer but, I'll put my ideas here because sadly it doesn't fit in the comment section.
I just watch the video and some of the reels they show as his works.
First, yes, in deed they make the marker a sort of invisible marker, but if you look closely, like a 0.25 speed and pushing space bar very fast to look it in slowmo, you can see a kind of "artifact" in between the girl's fingers that makes me think there's no invisible marker but a texture that are covering the marker. Maybe a cylinder that gets his texture from the video camera input.
Now, how I do that?
There are several ways to get the pixels from the webcamera, even Unity has one function. The trouble is, I dont want all the pixels but a little tiny part of the camera render, specifically the one's around my marker.
In my experience, and in his examples, they are using OpenCV, another unity plugin, so they can track anything, from faces, hands, or markers, so I can't be quite sure they are using Vuforia alone or in combination.
My idea is, with OpenCV you can catch your marker and his contour, then ask for the pixels outside the contour of your marker, those pixels will be the skin tone of the person and latter apply them as a texture over some plane or 3d model that can cover your marker. You can have the pixels at right side and left side of the marker and use a average function betwen them so it could look nice or if you like the adventures you can try to use some kind of digital images processing method to get bether results.
I'm not sure if you can have the pixels arround a marker just using just Vuforia. Honestly I've never try it before.
Well, that's my idea.
If you can get it better I'll like to hear about it.

Textures to Object in Unity / Vuforia

I'm trying to do some Augmented Reality in Unity using the Vuforia plugin. I've managed to get everything working (I'm using a 3d model of a car), only the position of the car relative to the marker is wrong when I come to preview it (click the 'Play button at the top and watch through the computer's camera - is 'preview' the right name for this?).
It should be sitting on the the marker in the center, but instead it's floating above the marker and off to the side by quite a bit. The positioning is definitely right in the program itself, so I'm not sure why this isn't reflected in the preview.
Also: at the moment the car is simply an untextured grey object. I realise the textures are included in a subfolder, however I can't drag the entire car's folder (including the Textures subfolder) into the ImageTarget, only the .3ds file itself. Does anyone know how to apply the original textures to the car?
Thanks so much for your help in advance!
Ben
Well, to start answering your question about the drifting away part, you've probably got a Rigidbody attached to your Car? Well, if that's the case, then Go to the Inspector where the Rigidbody is and you'll see constraints.
To avoid it floating off, you might want to check Freeze Positions for whichever direction it needs. Probably Y axis.
Now, I'm not entirely sure if you're using Vector.AddForce to move your objects, but if you are then just check if your car can move if you've put all constraints on.
If you can't then in your code trying using Object.Rigidbody.SetActive(true) when you need it to start moving, and Object.Rigidbody.SetActive(false) when its done.
On the other hand, if you aren't using Vector.AddForce() then remove Rigidbody component if you've used it.
As for the material. If you've got the material in your folder that you've downloaded then just drag and drop it into Assets. Now sometimes your car may be one solid mesh, but some times it may be multiple meshes. So which ever the case. Drag the material from your Assets onto the Hierarchy panel over your car mesh/meshes and it should turn into that color.
Hope it helps. :)

unity3d - Camera jittering?

For some reason when I run my game the camera which follows the player has a slight jitter to it. If I watch the transform the Y position values are fluxuating and the rotation is affected aswell. I can not think of any reason for this to be happening other than maybe having more than one camera as my water comes with a 'reflection camera'. I am using basic unity packages, and even when rewriting the camera follow script, the problem still occurs.
I know there is not much to go on here, as the code is minimal for this issue(using 3rd person controller and camera components). I hope someone has had this error in the past and fixed it or knows enough about unity to help me out here because im lost.
Much appreciated
EDIT
Dont know if animations could be effecting it but I thought id mention my model has animations
To resolve your problem. Click Assets->Import Package-> Characters Uncheck everything Execpt. SmoothFollow.
Drag Smooth Follow to your Camera. Drag your Character to the Target from Smooth Follow Script.
If this doesn't fix the issue. Try to remove your own script.

Scrolling Scene Background - Unity

My title might have actually been a bit misworded, as to be honest I'm not sure how to word it, but basically I'm making a game on Unity and I have my main scene and I am making a main menu however what I want to do is have a, I guess, camera slowly panning around the main scene as the background of the main menu. Not sure if I worded that right or what wording to actually type into Google to research it so I'm hoping you guys might be able to point me in the right direction.
Cheers guys,
Jason
As stromdotcom mentioned you can attach a script to the camera.
It's hard to tell what you're trying to do but if you want to circle the camera around a point...
Try making an empty game object in the middle of your scene and point the camera at it.
Make the object the parent of the camera (using the object and cameras transform properties).
From here you should be able to set the game object to rotate using a script, which should make the camera spin as it is a child of the object.
I have not tried this in Unity but I have used this technique in other programs so I'm assuming it will work. Sorry if it doesn't.
If your scene is already set up then you can attach a script to your camera which simply modifies the camera's transform to move it around the room. You can move and rotate the camera just like any other transform in your scene.
Im pretty sure what you are looking for is "Animation view". Unity has a tutorial on it: https://unity3d.com/learn/tutorials/topics/animation/animation-view?playlist=17099