I have a particle system BloodSpill that is Instantiated when the player dies by:
Instantiate(bloodSpillEffect, transform.position, transform.rotation);
However, it will appear behind all other sprites (background, ground etc.) NO MATTER what I do. I have the particle system as a prefab and it's sorting layer is set as the same as the player's both programatically and through the options. It's position on the Z axis is also closer to the camera than other objects.
Actually, if I drag one from the prefabs folder and put it in the scene it will appear in front of other sprites, but when I instantiate it through the line of code above it will not show up.
I don't know and am unable to find information on what the difference is between dragging and dropping it from the folder and using Instantiate().
Related
Alright, so I have a 2d rocket with a particle system shooting squares and triangles as thrust. The issue I am having is that, the particles that are emitted rotate with the rocket when the rocket and the particle system turn. The particle system is a child to the rocket. So if the rocket is going up, the particles emit downwards, but say I turn the rocket to be going down, those already emitted particles change their position to be above the rocket and start going up. How can I fix this?
Thank you!
One way to go about it is just to change simulation space to world.
With mode set to local, any changes to your parent game object, or the particle system itself, propagates down to all the living particles.
With world, new particles will match the position and rotation of your rocket, but the ones already emitted will retain their direction, as local changes to transform of ps/any other parent, will no longer affect them.
I make a 2D game in Unity. I have a player with BoxCollider2D and Objects with BoxCollider2D and the player can't go through these Objects like it should but when the player walks from down to the top (topdown PixelRPG) Than he got blocked very early. I will try to show it in the pictures. I tried to change the size of the colliders the layers and more but can't find a solution. ProblemCollision2DChest
Collision2DNPC
Collision2DWindow
NoProblem
NoProblemswithObjects
ProblemAgainfromdowntoTop
From my experience, it looks like you simply need to resize your BoxCollider2D to fit the player.
You can either use the Edit Collider button, and in the Unity viewport you can click and drag to change the size of the collider, or change the Size value in the inspector. Since your collider seems to be too large vertically, change the Y value to be smaller.
I currently have a 2D scene with a orthographic camera and I can move my player with my WASD keys which is great. I am wanting to add functionality of click to move as well but I am sort of lost on a approach. I have read/watched some tutorials and everything seems to revolve around the Nav/Mesh system.
My issue though is that my current scene for the ground and walls have Sprite Renderers and/or BoxColliders on them and I cannot have a Sprite Renderer and a Mesh Renderer on the same GameObject. Here is a quick screenshot of what I have :
Now I understand that I can easily create a click to move with a
Camera.main.ScreenToWorldPoint(Input.mousePosition);
and move towards that position with
Vector3.MoveTowards(transform.position, target, speed * Time.deltaTime);
The challenge for me now and the knowledge that I am wanting is if I have something like in the screenshot how can I add some sort of path finding system if I was below the house and clicked above the house that my character would walk around the house to get there?
Do I even need to edit my current sprites for the ground? I had an idea that I would just create extra GameObjects add a Mesh Filter and Mesh Renderer to it with "None" for the Materials and place them like puzzle pieces around my scene which would represent the areas I would want my player to move.
Is that approach I am thinking viable? Is it too much? Is there an easier way?
You can use "NavMeshAgent" to move your player. The "NavMeshAgent" component is attached to a mobile character in the game to allow it to navigate the scene using the NavMesh.
Once you have baked the NavMesh Its easy to use it -
navMeshAgent.SetDestination(target);
Reference -
Video Tutorial to create and use nav mesh, Unity Script reference, Navigation and Path Finding
Follow these steps to learn how to bake a Nav Mesh -
Create a 3D cube and scale it to (20,1,20) to make it floor(also rename it to floor).
Create another 3D cube, place it inside the floor and scale it by 5 on Y axis(rename to house).
Duplicate the cube from step2 and change its position so it doesn't overlap with other house.
Go to window > Navigation. This will open the Navigation panel with object tab selected.
SELECT the floor object in hierarchy. And click on "Navigation static" checkbox.
A popup will ask to enable navigation static for children, click "Yes".
Go to "Bake" tab in navigation panel and click on "bake" button at bottom.
You should be able to see the generated Nav Mesh in blue color.
Screenshot for the same -
I´m making a simple CAD application on Unity 3D using C# to configure closets. I'm trying to limit the movement of the shelves so you can move them only on the hole, so I have a dragger attached to every piece of the closet I want to move, but obviously they can cross with each other.
I thought I could use the collider system that Unity has to limit this movement but since I never worked with Unity before I´m kinda lost. This is my dragger so far:
mousePosition = new Vector3(Input.mousePosition.x, cubo_tmp.transform.position.y, distance);
objPosition = Camera.main.ScreenToWorldPoint(mousePosition);
objPosition.Set(objPosition.x, cubo_tmp.transform.position.y, cubo_tmp.transform.position.z);
I keep y and z components so it can move only in one direction.
Box Colliders are best for cuboid shaped objects.
In the editor, if you click GameObject > 3d Object > Cube, Unity will add a cube with a Box Collider to your scene:
If you want to add a Box Collider to a GameObject that doesn't have one, click Add Component in the Inspector panel and type in "Box Collider" to find it. It looks like this:
Note: If the IsTrigger box is checked, the Collider acts as a Trigger rather than a Collider.
A GameObject with a Collider will "collide" with any other GameObject that also has a Collider, with a small exception involving 2 Mesh Colliders that are both set to Convex.
EDIT: I think you are able to intersect the objects because you are modifying Transform.position directly in your code. This might override the collision behaviour.
Also Go to Edit > Project Settings > Physics and make sure your layer collision matrix allows collisions for the layers on which your objects are placed.
sorry for my bad english. I'm from germany^^
My question:
Is it possible to transform an empty game object into a shape that Looks
like a Piece of cake? I have a round terrain and I want to "cut" it in
three pieces of cake, because I want to play different music in all three areas. I Need These pieces of cake as a box/mesh collider or something like this, so I can Play different Songs if the Player collides with the box/mesh collider.
Ideas anyone? Please help me. :)
Is it possible to build an object in Blender for example and use it
as an invisible box collider?
Create the shape in Blender. Create a MESH COLLIDER. Assign your piece of cake model to the MESH parameter of the MESH collider. Scale it. Position it. set it as trigger and VOILA!
This would be the mesh you create in blender (RED)
then,
void OnTriggerEnter(Collider other) {
//play song
}
The other answers have covered options of generating a mesh outside of Unity and using it to make a mesh collider trigger for your music changes.
Other options:
Native Unity collider option:
Use two native cube mesh colliders to create a sandwich of two thin colliders at the borders where the music needs to change. Do some OnTriggerEnter/OnTriggerExit scripting to make the music change correctly when the player crosses the borders.
Pure scripting option:
Use the player position relative to the "center of the cake" point to calculate when to change the music based on where the player is located.