How to add nested transform to list instead of transfom of the parent gameObject? - unity3d

I'm trying to make the trajectories for enemies like list of gameObjects transforms.
And i want to add Path gameObject with all points of trajectory. And when i try to attach trajectory to enemy, i want to attach list of transforms, but instead that i attach the transform of the parent Path object.
How to unwrap points transforms in the list?
I've tried to google my issue, but i saw only nested prefabs and nothing about my problem

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.

unity snap object on another object

Im new to unity and I need to snap object to another object as its children.
I have hull, the hull has mounting point and turret. If i press... Num7, for example, the hull will change, and the mounting object changes as well, but i need the turret to lock on the new hull. And if i press Num4, the turret changes and it needs to stay locked on the mount as well.
Basically i need to remake this app, but now i need to know how to snap objects.. by their name or something.
https://youtu.be/6Kf-O6eJ4p8?t=634
When making a tank prefab, first create the Empty Object that will hold the rest of the objects. It'll be the parent object for the rest. Then add parts' objects.
When you remove the hull you just replace it with another hull, and since the turret is not the child of the hull object it will not be affected and will move as it was moving before.
Edit 1: Clarification: Each object is a separate tank (I'll just call it tank if you don't mind). Because your question didn't mention modifications at first I will update my answer accordingly. Each tank will hold 1 hull, 1 turret and 4 turret mods in a hierarchy.
So, what you should do is:
Make Empty Object in a scene, call it Tank;
Add Script as component, call it Tank;
This script will be subclassing MonoBehaviour;
Add Hull, Turret, Mods properties in the script, those are Game Object properties except for Mods, which is List of Game Objects.
Add a Hull Game Object (that I assume you already have) to the Tank Game Object. Make sure it's positioned correctly. Add Turret GO as Hull's child and Modification GOs as Turret's children.
Each Hull, Turret and Modification should have scripts attached to them.
Hull script should have snappingPosition property of Position type. Turret should have a List of Positions named snappingPositions.
After the objects are positioned properly note their Transform components. Values of each object's Transform Position are important for you, because if each Hull has different height or alignment the snapping point will have different position. What you want to do is to save that snapping point for each Hull Game Object inside Hull script. So go ahead and save Turret's position as a Snapping point in Hull and Mods' positions in snappingPoints of Turret.
Replace Turret with another one at the same position as current Hull's snapping point and align modification properly. Save Modifications' position as snapping points for this Turret.
Repeat 9 until done for all Turrets.
Replace Hull object and align turret properly. Save Turret's position as Hull's snappingPosition. Repeat for all 3 hulls.
Now each time when you are switching hull/turret/modification when editing just replace the turret, transfer all modifications by using SetParent (of their Transform component?), adjusting their positions to snapping positions from Turret script, then adjust Turret's position to snapping position on Hull script and destroy the old turret.
Edit 2: I now understood that it's a hull that has modifications, not Turrets. Therefore Hull should have Mods positions saved as modsSnappingPoints property. And when you change the hull you move all mods to a new one, update positions, move turret, update position and then delete the old hull.

how do i get a gameobject to conform to other gameobject shapes

Im trying to make a game in Unity and I want to have a gameObject fall and match the shape of the ground underneath it.
when the game is started:
what is does:
what I would like it to do
I'm pretty decent so even a hint in the right direction would be helpful.
thanks.
One way to do it is to duplicate the ground object and replace the falling object with ta modified version of that duplicate. How you can do that is to do the following on entering a collision between the falling object and a given ground object:
Make sure this falling object hasn't already collided with this ground object, such as with a fallingObject.lastCopiedGroundObject GameObject.
Find the y of groundObject's Collider.bounds.size
Add y to groundObject.transform.position to a new Vector3 newPos
Use GameObject newFalling = Object.Instantiate(groundObject, newPos, groundObject.rotation, fallingObject.parent).
Copy rotationalVelocity and velocity from the fallingObject's rigidbody over to newFalling's rigidbody, if appropriate.
Add, remove, modify components as necessary on newFalling, (such as replacing textures) to make it further behave and appear correctly as the falling object it is replacing.
Destroy the old falling object with fallingObject.Destroy()
Set the lastCopiedGroundObject of newFalling so that newFalling won't do this interaction with the same groundObject again, until another copy is done.
This will place the falling object above the ground object, and will let it fall using the physics engine to determine where it should rest on top.
One consideration is to instead use a List<GameObject> alreadyCopiedGroundObjects and to append the newly collided ground object to the list in the old falling object so that if the falling object touches multiple grounds, it will only change its shape to each one only once, so it won't perpetually oscillate between shapes in certain conditions.

Unity Gameobject is far away from the Move Tool

why is my Gameobject so far away from the Move Tool as you can see in the Picture down below?
I would like to have it centered at the Gameobject. How can I change this?
GameObject away from Move Tool
Screenshot of Hierarchy
Check the object in the scene hierarchy and make sure that the transform eg. x,y,z are set to 0.
If your object is a child of another object and they are not at the same position you are probably moving the parent and not the child object itself.
that Move Tool is the objects origin, and this might help:
"The easiest way is to create an empty object as a parent object. Then you put the corridor object as a child of the empty object. You can then alter the position of the corridor object so its positioned at the edge.
i found your answer here
note that its not exact, in your case, make an empty object, move it to where you would like your origin or move tool THEN add your other object to it as a child. you can then move it with the parents move tool(origin) right on top of your box.

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.