playMaker

Author Topic: Another question about inherit properties.  (Read 4434 times)

ryf9059

  • Full Member
  • ***
  • Posts: 100
Another question about inherit properties.
« on: June 18, 2013, 08:54:05 AM »
Last time we discussed the usage of meta fsm to avoid variable duplication. But this time around I have a different inquiry about extending the properties of fsm.

That is the polymorphism of fsms.

Says, I have a monster that takes damage from different types of weapons. There are many different types of weapon and they all have their own damage and effects. When collision enters, I use get collision info to get what type of object it collides. What I want to do is if the type is weapon it will automatically apply the damage from the weapon without knowing much about the weapon itself. Since I can't fine a way to do a weapon base and having all weapon extends it, I have to use object compare to compare every single types of weapon. That's not very efficient.

Any suggestions on how to deal with this type of problem?

Thanks

MajorIdea

  • Full Member
  • ***
  • Posts: 131
Re: Another question about inherit properties.
« Reply #1 on: June 18, 2013, 09:03:32 AM »
Maybe assigning a Tag for each weapon? Then you can detect the weapon used with a Collision Event and send the appropriate event.

ryf9059

  • Full Member
  • ***
  • Posts: 100
Re: Another question about inherit properties.
« Reply #2 on: June 19, 2013, 05:07:09 AM »
Maybe assigning a Tag for each weapon? Then you can detect the weapon used with a Collision Event and send the appropriate event.

Can I do that thru playmaker? This doesn't provide much abstraction tho.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Another question about inherit properties.
« Reply #3 on: June 19, 2013, 05:44:00 AM »
Hi,

 you need to define a convention for your weapon Fsm. Think of it as agreeing to define a common interface to all your weapons for example:

-- the fsm name must be "Weapon Interface"
-- it must implement a float variable called "damage"
-- it must implement a string variable called "name"

given these assumptions, your logic can access any weapon gameObject and simply use Get Fsm string value, you hard code the name of the fsm to "Weapon Interface" and hard code the variable to name or damage cause it's not going to be known at edit time, and then if you get the "name" and the damage then you had a weapon and you can process it.

Does that make sense?

you can also define event for your weapons, like "WEAPON / APPLY DAMAGE" and pass the hit target in the event data, then you don't even have to care about what is going to happen to the target and how damage will be applied. if it's a weapon it will respond to it, else it will simply totally ignore the call, even simpler!! you define "WEAPON / APPLY DAMAGE" as a global variable for convenience and it's all present during editing even tho you don't know yet the actual gameobject target.


bye,

 Jean

ryf9059

  • Full Member
  • ***
  • Posts: 100
Re: Another question about inherit properties.
« Reply #4 on: June 20, 2013, 06:56:10 AM »
you need to define a convention for your weapon Fsm. Think of it as agreeing to define a common interface to all your weapons for example:

-- the fsm name must be "Weapon Interface"
-- it must implement a float variable called "damage"
-- it must implement a string variable called "name"

given these assumptions, your logic can access any weapon gameObject and simply use Get Fsm string value, you hard code the name of the fsm to "Weapon Interface" and hard code the variable to name or damage cause it's not going to be known at edit time, and then if you get the "name" and the damage then you had a weapon and you can process it.


Can I do this by setting tags? Which one is better?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Another question about inherit properties.
« Reply #5 on: June 20, 2013, 07:24:14 AM »
Hi,

 Tag is good yes, tho I feel less powerful and flexible in the long run then a proper custom solution made purely in Fsm. but tags would do well here.

bye,

 Jean

ryf9059

  • Full Member
  • ***
  • Posts: 100
Re: Another question about inherit properties.
« Reply #6 on: September 01, 2013, 12:59:25 AM »
Hi,

 you need to define a convention for your weapon Fsm. Think of it as agreeing to define a common interface to all your weapons for example:

-- the fsm name must be "Weapon Interface"
-- it must implement a float variable called "damage"
-- it must implement a string variable called "name"

given these assumptions, your logic can access any weapon gameObject and simply use Get Fsm string value, you hard code the name of the fsm to "Weapon Interface" and hard code the variable to name or damage cause it's not going to be known at edit time, and then if you get the "name" and the damage then you had a weapon and you can process it.

Does that make sense?

you can also define event for your weapons, like "WEAPON / APPLY DAMAGE" and pass the hit target in the event data, then you don't even have to care about what is going to happen to the target and how damage will be applied. if it's a weapon it will respond to it, else it will simply totally ignore the call, even simpler!! you define "WEAPON / APPLY DAMAGE" as a global variable for convenience and it's all present during editing even tho you don't know yet the actual gameobject target.


bye,

 Jean

Hi sorry to bring up this post again, but can you elaborate how do I pass the hit target in the event data?

My question is, if I use a weapon to hit an object, it's the object that's receiving the event right? I also need to do something on the object's side like calculating final number according to object's defense so I guess it's more reasonable to process that using get trigger info on object. But from what you said sounds like I send this event on the weapon's side upon collision (pass the hit target in the event data, is this even trigger/collision enter or weapon / apply damage?). Kinda of confused. Please advise.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Another question about inherit properties.
« Reply #7 on: September 10, 2013, 01:46:48 AM »
Hi,

 You can go both ways actually. Both the projectile and the object being hit can be made aware of the impact. So the projectile can check that hit object and send an event to that object with values representing the damage to apply

Or, the object being hit can know what projectile just hit and apply damage to self.

In my example, I use the first version, the Projectile will fire an event "WEAPONG / APPLY DAMAGE" to the object being hit. the reason for that is that the object being hit is not aware of the projectile details, so it's easier to pass the data from a place that's aware of the various details then having to digg info. So for example the projectile has a power ( varying from projectile to projectile), sending the event "WEAPON / APPLY DAMAGE" will host in it s event data the damage power ( that's easy, it's define in the projectile itself), the object being hit simply get the damage from the event info, and done, it doesn't need to get the reference of the projectile, then look up the damage value to apply to self etc etc.

 does that make sense?

Bye,

 Jean

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Another question about inherit properties.
« Reply #8 on: September 10, 2013, 08:13:29 AM »
Nice thread, we talked about it here some, but I suppose it was a little vague.

What I'm currently getting into is what Jean recommended a while back and using a game object to store all of this common information, like damage for instance. It's just as simple to put the Damage for each weapon on its own FSM for easy delivery to colliders but I want to make a common place for those variables so I use Get FSM Float when a projectile is fired to load the damage into the projectile, and I can use that game object for all my UI data with damage and other things. It's a great organizational method and will help you avoid missing changes on things in sub-fsm's since you can just change it in one place and everything else grabs it from there. Working out great for me so far.

All of the weapons can be generalized with the same variable system like Jean talks about above, thats so you can communicate between any collider without issue with the events, var names and such. It's important to setup a generic system when possible to make it easy to create content later and implement it into the existing systems easily.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D