How to apply transform in Unity - unity3d

Is possible to apply a Transform via script in Unity?
What I mean with "applying" is setting the current position/rotation/scale of an object AS their default ones:
if a game object is rotated by 30° on the x axis, the x rotation value on the Inspector will display 30 of course. By applying the rotation the Inspector will now display 0 and the object will keep its rotation. 30° is now the default rotation of that object.
I know you can do this, for example, in Blender, but I don't know if it's possible to do it in Unity as well.

You cannot "apply" it directly to the object, but you can make a parent object, rotate this object when needed and "apply" the rotation or position to the child object, in this case the model.
Your hierachy should look something like this
- Parent (this is the object you want to rotate/position/scale)
- Child (this is the model, you "apply"/set default values to that object)

Related

Unity all objects have same position

I have a 3d building model in my Unity project. It has many children like doors, walls etc. The problem is, all of the children points to same position in the Unity world (24.97, -2.08, 19.35). Their transforms show this position. And this position is far away from their actual one. How can i fix this?
I tried freeing all children from parent but this didn't change anything.
I want them to show their real position, which appears with move tool when we click upon them.
Here is the image link
It seems that this is simply their pivot point exported "wrongly" from the 3D editor your model was made with.
This won't change until you export it correctly from a 3D editor (Blender, Maya, etc).
Unity is not made for 3D mesh modeling and therefore in Unity itself you can't change the pivot points.
There is a very simple fix
Add a new empty GameObject
In the Inspector go to the Transform component, click on the context menu and hit Reset (you also simply set it to position 0,0,0 rotation 0,0,0 and scale 1,1,1) assuming the pivot should be at 0,0,0
Now drag and drop all objects into the empty GameObject
=> You have now one parent object with correct pivot.
By wrapping it in a parent object the childrens pivots don't matter anymore. You can simply do all translation, rotation and scaling on the parent object with the correct pivot and don't have to care about that "wrong" position at all.

Importing an exported .FBX from Blender to Unity object transform issue

Alrighty,
I have a dumpster model I have exported from Blender as an FBX. The transform, rotation and scales have all been applied in Blender. when importing into Unity and then adding to the scene, the model is elevated and rotated at an odd angle to the transform as per the image.
The model has an armature for animating the lids an I have applied the location, rotation and scale on it as well.
Any one else come across this or know of a fix?Thanks
Blender image
Incorrect dumpster transform and location image
The problem is that Blender uses the right-handed coordinate system which means the Z-axis is pointing upwards.
Unity uses the left-handed coordinate system which means the Y-axis is pointing upwards.
To fix this, set the X-axis rotation of the model to be -90. Press Ctrl+A and apply rotation. The X-axis rotation will look like it is now 0 after that. Set it to 90 again and export it to Unity.
This 3 minutes video should also help you do this if you are still confused.
If you still have problems, check your animation. Don't apply it to your model and see if it's the problem.
Also as a side note, you can use blender files (.blend) directly with unity. So every time you modify them inside your project folder they change in unity as well.
The simplest way to solve this would be as follows:
Create a dummy game object (D)
Transform/offset the position of D to make sure your object's position align with the dummy parent
Put your game object as the child of the dummy game object D
You can then apply transform on D, rather than your own game object directly.

Positions of objects in the scene

My hierarchy of game objects is as follow.
Display(Scene)
Model(-4.708, 1.55, 14.4277)
Pass(4.7080, -1.5, -14.42)
handle(-0.0236,0.65690,0.149)
shaft(5.34,-1.0225,-0.1489)
head(-7.0912,-9.62,-0.5231)​
ball(0,0,0)
We can see Model and its coordinate on the image. Ball has position (0,0,0), but why it is located at the base of the Model?
How can I locate ball just beside the head?
Sounds like the origin point of one or more of the models is at off.
You can adjust this in 3d modelling software, or by making an empty game object inside unity and making your object a child of that object, then using the empty game object as the new origin point, you can adjust the positions of the child objects you assign to it.

Rotate an object with RotateAround to a specific value

I'm new in unity engine and try to rotate an object to specific value, but could not find any answer!
For example, I have an Euler angles (0,0,48) and my object in (0,0,340). I want give (0,0,48) values to my object with RotateAround() function to my object. Because it should rotate around of a point!
Unless you have a point in space you wish to rotate through, use Transform.Rotate(). that should be more than enough for you to rotate an object by (0,0,48) like you said.

How can find Center of circle to Unity?

I have circle, and I'm trying to find center and convert to Vector2.
For example:
circleLocation : new Rect( Screen.width/10, Screen.height/2.75, Screen.width/3,Screen.width/3);
centerofcirle:New Vector2(circleLocation.width/3, circleLocation.height/3);
But this example's not correct, the circle is not turn center. What is this formula? How can find correct center of cirle and how to convert Vector2?
Reading between the lines here, I wonder if issue has nothing to do with your code here, but with the rotation point of your steering wheel object, which isn't where you want it to be.
A common technique to change the rotation point of a game object is to make that object the child of another game object in the Unity Editor. Then set the position of the child object as you wish relative to the position of the parent object. Now, rotate the parent object. The child object will automatically rotate around the parent object's position, since it's transform (including position/rotation) is relative to it's parent's.
You seem to be defining your circle using a Rect so just use the Rect.center property:
circleLocation.center;