3rd person controller, allow camera through wall and prevent player - c#

im working for 3rd person fighting game between two characters.
I've setup camera to focus enemy and player in same time like Naruto Ultimate Ninja Storm 4, but when camera collide with wall the view angle will be change and both characters will not appear on screen.
in Naruto Ultimate Ninja Storm 4 there is transparent wall around arena which leave empty space between visible object (wall,rock..) and player but allows camera to pass it.
my problem I don't find method to let the camera pass this transparent wall and stop player to pass it.
I tried to get tag of object in collision and disable collider of object when is camera or vice versa but that allow character also to go tought transparent wall

You should create 3 layers, if you haven't already:
Player
Camera
Wall
Put each GameObject in the corresponding layer, then go to Edit->Project Settings->Physics, scroll to the "Layer Collision Matrix" and uncheck the collisions you don't want to have. In your case, you want the collision between the wall and the player, but you have to uncheck the collision between the camera and the wall.
Also, to make this work correctly, make it so that none of the characters, walls, and camera are separate gameobjects.
This is also very useful to remove any unnecessary collision and boost your game performance.

Related

How can I render contents inside a shape as a texture on the shape itself? As well as teleporting an object from one side of a mesh to the opposite?

I'm making a space game and I want the game to take place inside of a sphere or cube. I want the walls of the shape to render what's inside on the inside walls so it seems like endless space. Once the illusion of endless is in place I want to teleport the player if they touch the game space shape and teleport them seamlessly to the opposite side of the shape.
Edit: I just had an idea of how to teleport how I want. Maybe using ray casting to cast a ray behind the player and where ever that hits when they touch the edge of the shape to teleport to?
To answer question one I used a render texture. It's very close to the effect I want I just have to play with the perspective like they do with portals in portal 1 and 2.
To answer the my second question I went with raycasting. The player flys around in a sphere and casts a ray behind itself. Once the player hits the collision of the sphere they teleport to the point of the raycast. This works perfectly only for the fact when the player reverses on the sphere collider they escape the sphere flawlessly.

Unity TileMap Grid problem with creating a simple fog of war

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.

Making an object move through another and keep going?

I am currently making a sidescrolling game in Unity 2D where an enemy rises up, and then dives down to the player, but then keeps going until it is off screen, like how this image shows. 1 I can get the enemy to collide with the player but I can't make it keeping in that direction until off screen. How would I be able to do this?
You have to make your collider to trigger (it's a checkbox on your collider)
That means your object will not be affected by physics when it touch another collider, but it can calls functions.
You have to replace OnCollisionEnter/OnCollisionEnter2D, etc by OnTriggerEnter/OnTriggerEnter2D, etc.
Be careful, the parameter of the function may change too (Collision/Collider).

Unity 3D Character Stuck on wall-colliders

I am currently working on a 3D Unity game in which you control a block through a labyrinth made out of blocks and have to avoid spikes, moving enemys and other traps.
Here a picture how it looks at the moment ( you are the blue cube and have to avoid the moving pink ones ):
The problem now is, that when I move along a wall, the player gets stuck and stops moving until I move in the other direction again (every part of the wall is as big as the player because I am generating it from an image).
I already tried everything with Physics materials and friction but it does not get better :(.
The problem is that your BoxCollider of the player is probably getting stuck on the edges between two of the wall colliders. Consider "smoothing" the edges of the collider a bit so the player wont get stuck.
The default collision detection mode in Colliders is Descrete, it might jump through a small gap occasionally, you could set the players collider to CollisionDetectionMode.Continuous it will prevent the overshoot.
Try decreasing the Default Contact Offset in Edit/Project Settings/Physics
Changing it from 0.01 to 0.0001 worked for me
Source

Unity C# Bounce off Wall

So I'm making a 3D pool game. Basically I have a main camera that when you press a button it adds force to the cue ball based on the position of the camera, which works ok.
But whenever the cue ball hits the wall of the table, it just stops. I want it to smoothly bounce off the wall like a real pool cue ball would.
The cue ball is just a basic sphere Game Object. The walls are basic cubes with colliders.
I have tried Vector3.Reflect with no success. It seems to bounce back a tiny bit but then immediately stops.
Any help would be great!
You should create a PhysicMaterial with low or no friction (both dynamic and static), bounciness = 1 and Bounce Combine = Maximum and then apply that PhysicMaterial to the rigidbody of your sphere
You can do one thing.
Store the ball velocity when it collide with the wall, calculate the reflected direction through Vector3.Reflect and give the stored velocity to the ball in reflected direction.
Hope that this will help you...
Best,
Hardik.
To make bounce on wall we need to create physic material and after that we need to change the value of dynamic friction =0.3 and static friction =
0.3 and bounciness=0.8 and frictionCombine choose Average from dropdown and bouncecombine choose Average .
Hence the ball is start bouncing on the wall by using the upper property.

Categories

Resources