I am currently using Unity 3D to create a 3rd person game. But I am having an issue with trying to parent to the closest child transform of an object:
whenever the player comes into contact with a specific tagged gameObject, the collided game object becomes a child of the player. However I want it to child itself to the closest bone it collided at.
So far i have set up a for loop that searches for the closest local position to the collided object and found the Vector3 of the closest bone.
But now I want it to child itself to the transform with that local Vector3. If anyone has any advice on how to do this then this would be greatly appreciated. If you would like to see example code, then just say.
Thanks
One solution is to attach colliders to all all bones and then you can easily set up the parent child connection. In order to create all the colliders yo can use the ragdoll wizard. I used this successfully for a similar problem in my project and even on iOS the additional colliders (IsTrigger = true) don't decrease the performance.
Related
So I've been making this online survival game using mirror and I have come across an issue with spawning in a weapon for the player.
Apparently you can only parent an object to another networked object (when executed by the server).
When I was doing this in single player I had no issues obviously as I could just set the parent to my camera holder game object and it will follow the cameras rotations as expected.
Now for the client to see the other players spawned equippable, I can only seem to set the parent of the equippable to the player transform where the network Identity/transform is.
If I go to set it to the camera holder then nothing happens, the equippable will just spawn in at 0,0,0.
So with this said, is this the only way to do this? Have a ClientRpc tell the client to parent the equippable to the root of the player and then have code on the equippable to follow the camera?
I feel like I'm missing something important as this method seems quite finniky.
Thanks in advance.
I have tried putting another network transform on the gameobject I would like the parent to be set.. mirror doesn't like this, was hoping it would parent but it just goes to 0,0,0
I have tried to code moving the equippable with the camera but I wasn't getting good results so I thought I would ask here if there was a much easier and or practical way to execute this.
I'm working on a small project where the goal is to defend yourself from mass enemy hordes in a 2d environment. The goal is to have the game be physics based, with enemies pushing against eachother to create a feeling of chaos.
Now I have a setup with enemies, a player and multiple obstacles all with a Rigidbody2D and 2D-colliders (mixed types, including polygon2D collider). Now I want to have the enemies chase the player. The obstacles however are polygon shaped rigidbodies, and thus are able to move.
So I want the "navigation" mesh of some sort to update on the fly, and calculate a navigation path for many entities.
Note: I don't know how many entities yet, but let's say ~100.
The things I tried to far:
Using the built-in NavMesh package from Unity. This package does not properly support the 2D configuration of Unity
Using the NavMeshPlus package. This implements a NavMeshSurface2D component to work with the 2D environment. I got this to work, but the NavMeshAgent component to steer the enemy does not use the force attribute of the rigidbody component, but rather just sets the speed or position of the transform. If someone knows how to use the NavMeshAgent or the NavMesh API in a way to get the target direction/speed via script, that would also be a solution
I tried the A* package. Which also works, but creates a very jagged line as it only can move in 8 directions (up,down,left,right and diagonals). It also cuts the corners of the obstacles, and does not take into account the size of the object (enemy) itself, so it hangs at the corners.
If anyone knows a good package/extension or the location of documentation of the NavMesh part, that would be great!
Thank you in advance.
So I got it to work and will share the solution I took:
Using the NavMeshPlus package, I created a navmesh.
Instead of using a NavMeshAgent, I configured an agent type in the navigation window with the right physical dimensions.
Next I added a script on the enemy to function as a custom NavMeshAgent.
Add a NavMeshSurface2D reference to the script (Serialized)
Using UnityEngine.AI, call NavMesh.CalculatePath(), with the AI.NavMeshQueryFilter. This has 2 components, the agent and area setters. Both of those I get from the NavMeshSurface2D reference.
Now you have the path the agent has to follow!
By the way, I'm also aware this could be done by a custom Agent inheriting the NavMeshAgent class, I'm also looking into that. Time will tell which one will have better performance.
I'm attempting to develop a 2.5D fighting game in Unity, and I've gotten to the point of attempting to make basic collision between players function. I'm attempting to do so via collision boxes like those seen in the video here: (4:01 if the timestamp doesn't work)
https://youtu.be/m5yRLhAx4Ro?t=241
What I have attempted to do in order to replicate this system of collision is to make a collision box prefab with a dynamic rigidbody and box collider. A script instantiates a new one as a child of the player and destroys any existing ones whenever the collision box's size and position need to be changed. However, I've found that this does not work. I can get the players to collide with each other, but when I disable that collision by putting the parents on a layer that doesn't collide with any others, the collision boxes themselves will just phase through each other along with their parent objects, the players.
What I want is a system in which the players will be responsible for their movement, but the child objects (the collision boxes) will function as the players' colliders. If anyone knows a way of doing this, or any other way of achieving this sort of system, I would greatly appreciate the help.
Just add a Fixed Joint on the child object then connect it with the parent rigidbody.
TLDR: If possible using Bolt, how do I tell unity to find a child of a clone and not find the original. Essentially, find a child within THIS GameObject (clone), not the original prefab
Hello. I am pretty new to Unity but have been making progress using Bolt. What I have is a system that will assign a random material to a plane (Being the eye of the character) when the character is instantiated. The plane is a child of the head bone. There are two planes, a left eye and a right eye.
Left Eye Randomizer
This works well enough, but I have to create a system that copies the material from the left eye to the right eye. because if I reused the code then I would get two different random eyes. I used Find GameObject, but if I have more than one character, it will find any of that Gameobject rather than the one that is a child of clone.
Right Eye Copy Left Eye
I apologize if I did not explain this the best, but I would appreciate any help. Thank you.
Bolt just is a visual graph using the exact same types and API.
=> Same in code or in Bolt you would rather use Transform.Find which different to GameObject.Find does not search the entire scene but rather only direct children under the given Transform component.
I'm new to Unity and the is working on a personal project. In the following picture, you can see a blue plane in the middle, I want to use it as a ice plane and there should be no friction when user is walking on it. In another way, if I press 'w', the object should move forward until it hits an object. I know there's a built-in function called physic material, but it works only when the plane is tilt at some angle so that the object will slide down from the top to the bottom, but if the plane is placed in a horizontal level it will not work. Anybody has any suggestions for it, thanks.
Answering from my phone and off the top of my head, but look at using input.getaxisraw() to get your direction data then add forces. use triggers to stop the movement when you reach a trigger on another object. There were some good tutorials on Collisions and triggers on unity tutorials. To elaborate more, you can add colliders to the objects that you want your player object to interact with physically. So for your player object you can add code like:
OnTriggerEnter(collider c) {
// stop movement
}