playMaker

Author Topic: Force Field/Shield Collision problems  (Read 928 times)

curb47

  • Sr. Member
  • ****
  • Posts: 256
Force Field/Shield Collision problems
« on: September 18, 2020, 12:25:40 AM »
Hi,

Okay, so I'm very close to having a playable demo of my spaceship game, and I'm going into final tweaks and additions. One of the things that I left until last, because I thought it would be simple, was adding a shield/force field around my player spaceship which is activated at the press of a key.

Not so simple right!?

I've found plenty of tutorials about creating the visual aspects of the shield, and have a pretty cool looking effect done in shader graph, but no tutorials about dealing with the actual collisions, and sorting Tags.

Some details:

My enemies come in waves of 6, and each one has an 'Enemy' Tag. They have stats Health (10) and Damage (2), so when an enemy collides with the spaceship your health gets reduced by 2.

The spaceship has a rigid body, and a sphere collider and the collision event is set to detect the 'Enemy' Tag, obviously.

For my shield effect, I added a large Sphere as a child of the spaceship (0,0,0), added my shader graph material (looks good), and added a Sphere Collider to detect the collision of Enemies.

The problem is this:

Because the shield Sphere Collider is a child of the spaceship, when an enemy hits the shield it also activates the Health FSM and reduces the player's health by 2 (enemy damage). Not the most practical shield.

I've tried various things to get this right, but to be honest, I can't do it. I thought this would be an easy part!

I'm sure the solution lies somewhere in Tags and/or Layers, but when I start experimenting I end up losing the hit detection of the spaceship shooting (raycast - hit 'Enemy' Tag) and the collision event that sets damage done to the spaceship.

Maybe Compare Tags? Somehow?

I'm kind of going round in circles with this and would love some help.

All the best,

J.


djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Force Field/Shield Collision problems
« Reply #1 on: September 18, 2020, 02:39:33 AM »
Hi.
On activating / deactivating your shield you could set a bool to true/false.

Then on health handler you can do a 'Fsm Bool Test' (target the fsm with the bool) before deducting to see if shield is active or not.

The action can be found on the Ecosystem

curb47

  • Sr. Member
  • ****
  • Posts: 256
Re: Force Field/Shield Collision problems
« Reply #2 on: September 18, 2020, 04:33:12 AM »
Thanks dino,

I'll look into that suggestion.

Another glitch that's happening:

The shield is a large sphere, with a sphere collider, and the spaceship also has a small sphere collider around it. When I activate the shield, because the spaceship (and it's collider) is inside the large shield collider, the whole thing is freaking out as there is a collider inside a collider and hit detection is making the ship go crazy.

The obvious solution is to just disable the ship collider when the shield is activated, and vice versa for toggle on/off, but that seems a bit 'simplistic'. Is simple best in this case? Or should I look for a more elegant way of doing it?

Thanks,

J.
« Last Edit: September 18, 2020, 04:42:23 AM by curb47 »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Force Field/Shield Collision problems
« Reply #3 on: September 18, 2020, 05:13:35 AM »
HI i think you should use it as trigger instead

curb47

  • Sr. Member
  • ****
  • Posts: 256
Re: Force Field/Shield Collision problems
« Reply #4 on: September 18, 2020, 07:21:28 AM »
Yeah, I though about using it as  a trigger, but I really like the physical material I've got on the sphere, as it has a nice comical bounce to it, and the spaceship rebounds like a pinball.

I got the Fsm Bool action you mentioned, and I've got it working. It's simple, but I really don't need anything elaborate.

Thanks for your help.

J.