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.
Related
I have a procedurally generated dungeon BSP on a Tilemap Grid. a TileMap collider has been added to it.
I planned to do it simply, since my TileMap contain a SpriteRenderer, I add the color 0,0,0 to it like a black fog of war, and if I can't see it well or have already opened it i would repaint them with 0.5,0.5,0.5, and the area around the player would make 1, 1, 1. and that would be cool, BUT I only can get tiles from the map via VectorInt, or via an index and a copy of the array. Can I access each cell, somehow through a collider? To use something like Raycast or Overlap Colliders.
any collider or collision tells me about the TileMap map. Or do I still need to create each tile and attach them to a game object or Scriptable object? I'm confused, tell me, I reviewed many tutorials and questions on this issue and got confused
I don't completetely understand, but I'm pretty sure you want to add a tile during runtime? Or you at least want to change the tile so that it's black or has a fog of war?
First off, I found this link: How can i place a tile in a tilemap by script
However, that would be difficult, having to have some kind of array, or possibly 2d array, of all the tiles for when there shouldn't be a fog of war.
My suggestion is using a Sprite Mask , and setting the tilemap(the actual ground) to not interact with the mask, and having a big fog of war sprite, like a big black cloud that might follow the player around so that it doesn't need to be a massive sprite, and set it's sprite interaction to visible outside mask.
Finally, make a sprite mask that follows the player around, and therefore will remove the fog of war around the player.
Another thing is to make a big cloud sprite with a hole in the middle, and have it follow the player around. That way, there's a big fog of war, but there's a hole in the middle so the fog is not around the player.
I'm making a small game using Unity for a school project. The purpose of the game is to control a ball, collect coins and reach the goal area. My goal area is made up of a capsule that I have flattened out and put a sphere collider on it. How do I get to shift scene/level when reaching the goal area? What code do I need to write?
You will need to set the Sphere Collider to "Is Trigger" and add an OnTriggerEnter method to a script that you have attached to the goal area game object. Make sure the scene name matches a level that you have defined in the build settings.
public String NextLevelName;
private void OnTriggerEnter(Collider other)
{
SceneManager.LoadScene(NextLevelName, LoadSceneMode.Single);
}
First of all, you have to add all scenes into the build settings. Then write
SceneManager.LoadScene("Your Scene Name")
in your script when you reach your goal area.
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.
I try to do the following: I have a point A at -4x-4y and a point B at 4x 0y. I want to make a colliding line from position A to position B.
I tried to do it with a linerenderer but I can't get the line to collide with my other 2d objects.
My other tought was to calculate the center of the points and the rotation and do it with a box collider but that seems to be really complicated and hacky.
Is there a simple way to achieve this?
Thanks in advance
You can use PolygonCollider2D, it's automatically create collider for sprites, and if you are not satisfied results, you can edit it by clicking Edit Collider in inspector, or trought Unity's API.
I think you must have a Rigidbody2D attached with your other 2D object. Then this will work 100%. You can use any collider it doesn't matter.