Unity- Colliding Passing Through - unity3d

I made airplane shooter in Unity. First I make player and I already make all the code. And it works well. And then now I want to change the player object. I had already put the script and give same name and tag as the used player that I make. And the colliding is a mess. I can shoot enemies down. But the enemies can't shoot or hit me. The enemies bullet and the enemies passing through my player object.
I don't know why. Please help me to find the problem. Just tell me the possibilities of this problem cause.
Here is the screenshot of my new object component

Check if your Collider has the "Is Trigger" checked, that may be causing the error.

Related

Unity: My enemy prefab can't find the player on the scene

So my problem is, that I have a GameObject, which spawns enemies, and it has a variable, where I can put my enemy prefab. My only problem is, that my enemy doesn't follow the player.
I made an enemy prefab, with the A* path-finding algorithm, I included the AIDestinationSetter also. The A* works just fine when my enemy is in the scene, but when I try to spawn it, it somehow doesn't seem to know what to do. Any ideas what is wrong?
Thanks for all help, much appreciated!
If the problem is setting the target as the player prefab instead of the player in the scene, add a tag to the player and in the script, get the reference of the player in the scene using
target = GameObject.FindWithTag("Player");
Note: Works only if there is only one game object with the tag "Player" in the scene and if there are multiple of them, this method returns the first one it finds.
To get multiple players as targets, use
targets[] = GameObject.FindGameObjectsWithTag("Player");
For more information, refer:
https://docs.unity3d.com/ScriptReference/GameObject.FindWithTag.html
https://docs.unity3d.com/ScriptReference/GameObject.FindGameObjectsWithTag.html

Trying to get information from multiple gameObjects in a scene

Hope everybody who's reading this is having a great day!
Anyways I'm having a little bit of a problem with a system I want to implement in my Unity Project, basically it's a Enemy ID system. The idea was whenever the player enters in contact with a enemy, it would get it's ID and would use it to instantiate them in a battle scene.
This is the Scriptable Object I'm using as a template for the enemy stats and ID
This is a example of how would the enemy stats look like
And this is the script that check the collisions with the enemies
My problem stand from that I can only get information of one kind of enemy, I've tried making the enemy check the collisions so they would get their own ID, it worked but it would be hell to parse this information through scenes. Is there a way to make the script which check collision detect more than one type of enemy? Help would be very much appreciated!
I would leave a comment, but my reputation isnt quiet high enough yet. Is there a reason you cant use raycasting? I believe you are only evaluating a single gameObject.
Enemy = collision.gameObject;
You then compare that single enemy object
if(Enemy.CompareTag("Enemy")) {
}
You should likely store an array of enemies and check each one on collision enter.

Unity colliders behave in a weird and unexpected way. How to solve that?

Ok so I know it's me and not the collider that is not working but I just don't understand why. In this clip you can see me moving my mouse over the enemy ship. I continuously click, and the onClick event makes the border around the enemy ship appear: https://gyazo.com/c1379139f0fe3d22ff510a0a1b45ab96 The hitbox is just a square around the entire ship so I was inside that all the time. After I managed to click on it I can shoot it but the cannonball just goes through it: https://gyazo.com/1914faecabe9c9a36cc1f5dc2632184c Here you can also see that the ball collides with the island as it should. I can also move the enemy ship with my own ship no problem.
The only thing every enemy has in common with this bug is it ONLY happens when the ship is close to an island.
If anyone could help solving that issue Id be really glad I have run completely out of ideas :(

Child Components with rigidbody

Context
I have in my project two elements. A player (just a cube) and some eyewears.
When the glasses aren't attached to the player, i want them to have properties of a Rigidbody. But when the eyewears are attached to the player, i want them to be a static object, so the player can process the collisions and physics.
I have tried:
DestroyElement(rigidbody) when the player pickup the eyewears. When he leaves them, i recreate the rigidbody with AddComponent
It worked nice, but in the future other elements will be attached and they will not share the same properties of rigidbody. I though maybe i could save the rigidbody instance, so when the player leaves the glasses i assign it to them. I could't.
AddComponent don't accept arguments.
Then i tried to set "kinematic mode" when my player wears the eyewears. It didn't go well, my player can't jump anymore and sometimes he glitches in the floor.
How can i resolve this?
GameObject.AddComponent does take an argument, or a generic argument (preferred):
go.AddComponent<RigidBody>();
this is also possible, but deprecated, since you lose type-safety:
go.AddComponent(typeof(RigidBody));
However, RigidBody is not meant to be added/removed, and in your case I would say that kinematic mode is the way to go... but I can't tell why you're experiencing weird results with it.
Thanks to R Astra i checked again the eyewear collisions and i found out the problem. I had enabled the Convex mesh.
The col was causing trouble because the back meshes were inside the player
So, quickly i copied that eyewear and generate a new mesh. It worked!
Thank you very much!

Unity Sprites - Collider not working Properly

I was following a tutorial on how to create a simple game called pong. As I was working on it. I stumbled on a bug that when the ball is to fast it will it passes through the paddle without colliding with the collider
As you can see in the screenshot
Is this some kind of a bug in unity? I need to get rid of this and don't want to have this in my game.
by the way this was the tutorial I was following . Brackeys
What do you mean by 'bypass the player control'? Do you mean it passes through the paddle without colliding with the collider, even though it should? Or does it get stuck? The screenshot makes it difficult to tell.
Either way, the first thing you're going to want to try is changing the collision detection setting of your Rigidbody2D component from 'Discrete' (the default value) to 'Continuous' or 'Continuous Dynamic'. Fixing this sort of issue (collision errors for fast-moving objects) is exactly what those options are for.
Source: http://docs.unity3d.com/Manual/class-Rigidbody.html