Loot popping out of chest - diablo style


(bill) #1

Hey all :smiley:
First of all, I apologize in advance if there is already a thread about this, but I searched and couldn’t find one.
I’m pretty sure this is a very small blox event, but I can’t seem to nail it, since I’m still very new to Unity and PlyGame.

I followed a guide by @Ryan (thank you Ryan) on setting up chests with loot and I can’t believe how easy it was. Anyway, I click a chest, it plays the open animation, and loot appears beside it by an offset I applied. I want to take it a step further and have loot pop out and fly through the air a bit before landing and becoming intractable.

Here is my approach: Add an “On Start” event to my plybox on the item that will drop:

But it doesn’t do anything, it just behaves exactly the same. Perhaps “add explosion force” doesn’t do what I think it does? (edit: yes, there is a rigidbody on the item and it’s kinematic)
Can anyone point me in the right direction?

Thanks in advance!!


(Marshall Heffernan) #2

Did you mean to say you have a rigidbody and it’s not kinematic?

Is Kinematic: If enabled, the object will not be driven by the physics engine, and can only be manipulated by its Transform.

Ensure this checkbox is un-checked.

I’ll try out explosion force while you’re checking on that.


(bill) #3

:smile: oops! Well, that’s embarrassing. For some reason I thought it was the opposite.
Anyway, I’ve unchecked it and now it just falls through the ground. It has a box collider on it too, so I’m just working on that part. Thanks for pointing that out.


(Marshall Heffernan) #4

Alright, figured it out :wink:

  1. Change MODE from Force to Impulse

  1. in “force=” I used a float of 6.

  2. in “pos=” I used…
    [Get Position of Self] - [Vector3 from XYZ]

I dropped in a [Random Float] for the X and Z, between [-1 and 1]
I dropped in a float of 3 for the Y.

This means the explosion (or impulse, in this case)
will happen three units below the item & a little left/right/forward/backward.

(click to enlarge image)


(Marshall Heffernan) #5

No worries! If you’re ever curious, just click the quesiton mark, next to a component!

and the Unity Docs will open right up, to the corresponding page!


(bill) #6

Thanks for the info!
This works beautifully, but how do you get it to stop falling through the terrain?
I wrote a script in C# that calls an IEnumerator that waits then makes it kinematic around the time it hits the floor, that makes it stop going through, but I dont think thats a great way to do it.


(Marshall Heffernan) #7

Falling through the floor would be because the collider is too small.

You can actually do this in plyBlox, if you’d like.

The “Trigger Event” plyBlock, from the Flow category, comes with an “after x seconds” field.
Just throw a float in there!
(triggering a Common>Cusom plyBlock event).


However this shouldn’t be necessary.

If I remember correctly, when you “DROP” a plyGame item, the “Floor Art” model will be instantiated.
It is GIVEN a rigidbody component, if there wasn’t one already.

Then, once the velocity hits 0, the component is removed, all on it’s own.


Having said that, it might be worth it, to just try the “explosive/impulse force” block, EVEN if there is no rigidbody, to see if this little trick would work!

(but once again, if a collider falls through your floor/terrain, it is due to the collider on the item being too small.)

(a Plane comes with a “mesh collider”, which i think works, and a Terrain comes with a “terrain collider”)


There was something else I wanted to mention but I’ve forgotten. I’ll let you know if I remember.


(Marshall Heffernan) #8

Oh, I remember.

Having a big collider on a small item might be strange.

  • It might land on the wrong side of the collider, causing the weapon to “stabilize” unrealistically, like balancing on the pommel or hilt of a sword.
  • It might be hovering (noticably) above the ground if you make the collider too large.
  • Your Player might have to step on top of the collider, which will seem strange.

I haven’t tested this issue too much, but you could try using box colliders of varying sizes, or a mesh collider with the “convex” checkbox checked.

I would recommend against using a sphere collider or capsule collider, as they might roll around, unrealistically, then “settle” in an awkward position.

One thing I do know the answer to, is avoiding unwanted collision.

Simply go to…

Edit > Project Settings > Physics

and uncheck the box, where the “Player” and “plyItem” layers meet.

(thus, allowing you to walk through items on the floor… if that’s what you’re in to.)


(bill) #9

I’ve shaped the box collider to be very close to the shape of the weapon that drops. I was careful of that.

I just tried this mesh collider with convex, I even tried a collider on my terrain ( even though it already had a terrain collider on it). Nothing is stopping it from passing through the floor. I have an On Collision Enter blox and it wont trigger. Apparently, I’m misunderstanding these objects, so I’m just going to hit up the documentation, and I’ll check back in.
Thanks for the info!


(Marshall Heffernan) #10
  1. the “On Collision Enter” checkbox needs a rigidbody, i think. I’ve never used it.

  2. I always use “On Trigger Enter” instead.

(but to do this, you’d have to check the “is trigger” checkbox, and… well then the collider would definately go through the floor)

Have you tried making the collider really huge? like… three times the size of the weapon?

There’s a certain size you need (for whatever reason) to collide.

I don’t know a good fix to this, besides increasing the size, but… I’ll definitely put it out there, when I find out.


(bill) #11

Yeah, I have the rigidbody on it. I’ll play with the sizes next.
I tried to make a totally seperate 3d Cube with a collider, and I get the same problem.
Do you see anything wrong with my weapon item prefab? It seems to be the problem, but I’m not sure…

(edit: also tried as a trigger, and on trigger enter event blox will not fire)


(Marshall Heffernan) #12

If a regular cube is falling through your floor there’s definitely a problem, I’d say there’s nothing wrong with the item, if this is the case.

I’ll do some google searches to see why rigidbodies would blatantly fall through terrain in Unity, in a little bit.


(bill) #13

Well, what I did was dropped my weapon (the loot) prefab onto a cube and it fell through it.
If I drop a cube onto my terrain, it will bounce off the floor.
So if you don’t see anythign wrong with my weapon prefab, then… I will try a different object? I really would like to get to the bottom of this. My OCD will keep me going all night if I don’t get this :slight_smile:!
btw, I really appreciate you helping me on this.


(bill) #14

Well, I’ve tried everything. I made a new object, attached the “item” script to it and defined it as equippable, and assigned a slot. I attached a rigidbody and a box collider, and it just falls through the floor.

If I uncheck the item script, it lands on the ground nicely. So something in this item script is causing this. I’m going to keep digging. Also, I have coffee this time, instead of whiskey :smile:

Also, I think this is set up properly:


(bill) #15

Solved.
I found another thread in the forums: Finding the “Drop” item in Scene Falls through the terrain
Leslie showed a diagram on how to set up the item.
I had put the box collider on the parent, when it needs to be added to the “art” with the mesh renderer. That was a painful lesson, but now I can move on :slight_smile:


(bill) #16

Well, unfortunately I can’t move on. There’s two issues I’ve been trying to solve for hours and I am getting nowhere.

  1. When the dropped item is picked up, it behaves very strangely. It appears to apply the explosive force again, and move all over the place as my characters hands move while idling. I tried to reset the position in the On Equip blox, I tried resetting the items prefab location back to 0,0,0, … None of this appears to have any effect.

  2. I tried to apply the dropping effect to another item, and it falls through the floor with identical setup (Gladius hits floor, Longsword doesn’t). There is no difference between these items except the Mesh texture:

Any suggestions would be greatly appreciated!


(bill) #17

Okay… Well I was abandoning this whole idea, and instead just trying to make the item appear inside the chest, when I stumbled on a simpler way of achieving this effect without explosive force in the On Start. :


#18

If you want the loot to fly out and not have to worry about the collision size and whatnot you can simple just do what Diablo 2 does and just:

  • have the object spawn above the chest
  • when spawned set rotation to the forward rotation of the chest with some give on the Y either positive/negative
  • then from there simply spherecast to a point on the floor in front of the chest in a small radius
  • then with that hit point in hand, lerp the position of the item to the hit point while also lerping the Y on a curve from origin to destination so that way it gives the impression of arcing loot flying out
  • finally you can just run a check to see if the object is at the destination either by raycast or a vector 3 distance check and if so then just disable/delete this script off the item so its not running anymore

And pretty much youll have a working flying loot system just like in Diablo 2 etc. Ill create a small demo for you to showcase this but it wont be up till the morning.

have the object spawn above the chest


#19

Ok here is the unitypackage for the demo of this system i created. Very simple yet effective for a simulation of this effect.


DOWNLOAD


INSTRUCTIONS

  • Create the plyGame item the way you normally would, then attach the IAG_LootItemArc script & correct layer to the item (plyGame default item layer).

  • Create your chest and attach the IAG_LootArcSystem script to it

  • Add the created item to the Item List on the chest
  • Finally, exclude the plygame layer from the layers on the chest

Now just press play and turn the Spawn New Item bool to true and watch the loot fly out. I attached screenshots of my demo included in the package but obviously the plyGame components are missing off the item and theres no interaction with the check its just through the bool manually.

So, your job will be to edit the list to allow for more flexibility and to make the check spawn plyGame loot instead. Its quite simple and can be done in about 5 min tops i just am too tired and am going to sleep. Let me know if you didnt figure it out by the end of the day and ill help again.


(angell) #20

Hello, i know that i may be 2 years later but could you please refresh the download link? thank you.