playMaker

Author Topic: Shadow Ai  (Read 700 times)

amirkhan

  • Playmaker Newbie
  • *
  • Posts: 17
    • View Profile
Shadow Ai
« on: December 10, 2018, 01:42:45 AM »
Hello guys i am making 2d top down game and i want to make this tyoe of function.

when player goes into the shadow area it will hurt him and drain drain the hp
if he goes into the light area it will not hurt him

i know how to implement this but the problem is that if the shadows are dynamic like 2ddl asset
then the shadow will change like if the player has lantern or torch or something or light source and he goes to shadow area i want him to not be demaged untill he hass the light source if goes out the shadow will engulf him and it will drain his hp

like darkest fear game of java me
so how do i obtain this in unity :-\

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4781
    • View Profile
    • jinxtergames
Re: Shadow Ai
« Reply #1 on: December 10, 2018, 03:06:22 AM »
Hi.
Maybe you can use a simple bool (isUsingLight) to check if player has a torch or lantern active, before damaging the player.

You could also use a trigger area on the light source so that :
When the player is inside the light source, set 'isUsingLight' to true (or call it isInsideLightsource' for example)

amirkhan

  • Playmaker Newbie
  • *
  • Posts: 17
    • View Profile
Re: Shadow Ai
« Reply #2 on: December 10, 2018, 03:24:07 AM »
thats true but what about if the shadows are dynamic and can change

i want to make it like this game =
will it have any problems

Thore

  • Sr. Member
  • ****
  • Posts: 370
    • View Profile
Re: Shadow Ai
« Reply #3 on: December 10, 2018, 12:08:53 PM »
thats true but what about if the shadows are dynamic and can change

i want to make it like this game =
will it have any problems

What exactly is a “shadow” in your game? Do you want to make use of some property, like cast shadows, created by actual lights? This seems not trivial. I wouldn’t do it that way, but if so, find out more about how light system works, and then you can look for building something with playmaker, ask for actions etc. A bit simpler, but still not optimal, you could build something around colour picking values and use that to determine shadows.

I think you should keep it simple. Consider a game object with a simple trigger collider on it, lets say a sphere or circle, attach this to a spotlight. Now the spotlight represents “in the trigger”. Likewise, think without the metaphor and purely in mechanics. Then dress up the mechanics as you want. For example all areas that are lit, also have a trigger roughly around the area you want. They can move around, be switched on and off and so forth.

Now you can use simple mechanics, global events like On Trigger ... to determine if the player is in light (or shadows), and make bool checks and hook up everything else to that.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4781
    • View Profile
    • jinxtergames
Re: Shadow Ai
« Reply #4 on: December 10, 2018, 04:32:54 PM »
Hi.
With trigger areas on light sources that can work dynamically yes.
when light goes off, disable the trigger.

You can also make a more advance system than disable. for example if full light do 0 damage, if half dark do x damage. if dark do xxx damage.


tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 745
    • View Profile
Re: Shadow Ai
« Reply #5 on: December 10, 2018, 11:21:40 PM »
The asset store has some different shadow detectors. https://www.assetstore.unity3d.com/en/?stay#!/content/84042

Realtime lighting is easier, because you can do raycasts to see if you are within line of sight of a light and then measure your distance.

Baked shadows are more tough, as the same method does not apply.