Inspector screenshots please!

I have a series of problems that I believe comes down to RigidBodys and and Colliders on different prefabs but not sure how they’re meant to be set.

If someone could provide screenshots of their inspectors for Player, PlayerLaser, Enemy and EnemyLaser that would be all sorts of awesome!

Hi Dominic,

If you also list/outline the issues that you are having, with some specifics, those of us without screenshots to provide to hand may also be able to chime in and help :slight_smile:

Well I could do that, at the risk of boring y’all!

Basically my game works but if I switch off trigger on player ship it goes wrong in a different way to Brice’s - bullets pass through ship rather than bounce off.

I’m not sure if I have something set differently that might cause problems in a future section - and I couldn’t find bits on video where Brice set variables for each prefab for me to compare with his.

hehe, no worries, I don’t have a lot on this evening :wink:

So, if you turn off, e.g. uncheck the IsTrigger field on the collider, there is nothing to capture the event OnTriggerEnter2D, and hence the enemy lasers probably aren’t being destroyed, until they hit the collider which is out of the viewport to tidy up.

If you want things to bounce off, you need physics, and for that, you’ll want a Rigidbody2D component on the player ship, I’m assuming you maybe don’t have one at the moment? You would want one on the enemy lasers as well.

Collisions with the Rigidbody2D component will be caught using OnCollisionEnter2D instead of OnTriggerEnter2D.

Does this help?

I’ve gone out now but I’m nearly certain I have RigidBody2D and Collider set for each of the Player ship, enemy ship and their respective lasers.

I don’t want things to bounce off - was just trying to replicate Brice’s results and couldn’t. Perhaps I should just worry about it if it becomes an issue in future.

Ah I see, I don’t really recall what Brice demonstrated to be honest with the triggers, having just checked an old copy of the project I have here, IsTrigger is enable, and the player ship and enemy laser do have the Rigidbody2D components.

Happy to take some screenshots of any specific items if they are of use, but I have upgraded the project to Unity 2018, so there may be some differences if you are using an older version. Let me know, it’s no trouble. :slight_smile:

Brice had forgotten to click istrigger for the player ship and the bullets we’re all bouncing off, mine didn’t do the same when I hadn’t selected istrigger.

If you want to send screenshots I’ll appreciate it greatly but only if it’s no trouble as it’s not an immediate problem.

Perhaps this is caused by a combination, e.g. you unticked IsTrigger for the collider on the player ship, but what about the enemy lasers? If he had that unchecked on both then I think you would get the bouncing off effect, if either or both have IsTrigger enabled then you wouldn’t see the bouncing effect.

Might be worth a quick test, just to satisfy curiosity, as and when you are back. Failing that, happy to send screenshots through, presumably just the Inspector view showing the components for both enemy laser and player ship?

Ok, I decided to be super diligent, I tried all possibilities, I made sure to click apply after each change and then when I was playing I paused so I could double check each prefab had the right setting and I wrote it all down on paper as I went, my results:

EnemyLaser Is Trigger, Player Is Trigger = Laser Destroys player

Enemy Laser Not Trigger, Player Not Trigger = Laser passes through player, neither effects the other

Enemy Laser Is Trigger, Player Not Trigger = Laser Destroys player

Enemy Laser Not Trigger, Player Is Trigger = Laser Destroys player

Like I say, the games working but that behaviour doesn’t seem quite right.
(They both have RigidBody2Ds)

Ok, I think I can replicate the effect you are missing…

If you uncheck the IsTrigger on both the enemy laser and the player ship, and then change the player ship’s Rigidbody component’s Body Type to Dynamic instead of Kinematic.

These options were not available in the version of Unity which the original course was created against and as such I suspect that the Dynamic option was effectively the default.

If you want to make it even more funky, create a Physics Material 2D, give it a bounce value (a value of 2 is quite fun) and then apply this as the Physics Material for the Rigidbody2D component on both the enemy laser prefab and the player ship.

I don’t think this was a step missed on your part, just a slight change in default behaviour in the newer version of Unity.

image

I’m using Unity 4.9 - I can deselect ‘Is Kinematic’ but I can’t see an option for ‘Dynamic’.

Is Dynamic what you get if you untick ‘Is Kinematic’? - I tried unticking it without bullets bouncing off.

My apologies, I assumed your were using one of the more recent versions of Unity, e.g. 2017 or 2018.

I no longer have any old versions of Unity installed, I removed them all about two weeks ago as I had so many, so I can’t really compare.

The IsKinematic setting indicates whether the Rigidbody is under the control of, for example, animation or script as opposed to the physics engine.

Without being able to play with a version of it here this will be a little bit of guess work, but try unchecking the IsTrigger on the collider on the playership and the enemy laser and unchecking IsKinematic.

You may find that your player ship disappears off of the screen at the bottom if gravity kicks in…

Never apologise Rob.

That worked! Thanks, I was almost certain I’d tried every possible combination of ticked and unticked boxes but clearly not. My curiosity has been fully satiated and I’m now ready to move on to the next tutorial.

1 Like

Phew! hehe… If you take a look at the manual on the Unity website specifically for Rigidbody2D it goes into some good detail with regards to the combinations of what happens with what.

The more recent documentation covers the Body Type (Dynamic, Kinematic, Static), which is a slight change in the API compared to the version you are using, but the information should still be fairly useful and you’ll be covered for when you move to a more recent version of Unity :slight_smile:


See also;

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms