Creating a moving soda can

Again for my university project we wanted to create an interesting mechanic where when the player crashes into a can of soda, the can would fizz up and create a jet of soda that would propel it along, bouncing of walls and general going in random directions. If anyone remembers shooting the propane tanks in Far Cry 2, that is what we’re aiming for.

Thanks
Alex

Hi Alex,

I have a very basic setup that could get you started. There will more than likely need to be adjustments if you want to have more control over your random bouncing soda can, but this at least a starting point.

This is the setup I started with:

  • Place your Soda Can asset in your viewport.
  • Place a Physics Thruster in your scene attached to your soda can. You can attach this by dragging the PT onto the Soda Can in your scene outliner to create a parent/child attachment.
  • Angle the physics thruster so it doesn’t shoot straight down (found this to give better results)
  • In the details panel for the physics thruster you’ll need to set a value for the thrust. Mine is set to around 50k but that can depend on the asset. Play with values until you get a result you like.
  • For the collision on your soda can, I found it better to use a capsule rather than box or cylinder with a flat face.

Next create this blueprint in your level BP:

I’ve setup up a Flip/Flop to activate and deactivate this on key press. Again, this is starting point, you’ll probably want to extend this more so as with my simple setup it’s easy for the can to get stuck pointing in a certain direction on the wall and no budge until deactivated. That would require more BP logic and some ray traces with branch nodes to indicate whether it’s stopped or needs to bounce in a specific direction or style. This method is truly random and all over the place though.

I hope this helps!

Tim

Thanks a lot, I’ll give it a shot :smiley:

I managed to get the can falling over when the player runs into it however I can’t get the physics thruster to activate and send it flying :confused:

Have you made sure that the thruster is attached to the can? Also, make sure that the thruster is using a high value to move the object. Typically, I start with really high values, enough so that I just see it shoot off and don’t know where it went, then I’ll start tweaking the value down until I get something more in line with what I would like.

As a test as well, are you using the key-press setup I’ve outlined above?

I have used the exact set up you outline, the thruster is attached to the can and the values are very high. The only thing I can think of is the fact that I don’t have a button to activate it as I want the player to knock it over to activate the thruster.

I was able to do this without the key press by getting rid of the flip flop since it’s not on key press (mainly my test method for enabling and disabling things) and change the key press node to an on actor hit event. You can get this by selecting your soda can, right click in your level BP and set an event for actor hit.

Give that a shot and see if you get the reaction with collision. This is just a basic starting point. Using ray tracing to detect hits of where the can is and changing it’s bounce direction would be the next step if you want it pinging around a room. This will solely be dependent upon the collision capsule and often resulted in it just bouncing once or twice an then the thruster keeping it forced against the wall or floor.

Just wanted to let you know, I’m looking into creating this in my spare time. I don’t know when I would be able to get this fully setup, but I think it would be a neat tutorial for others as well. I’ll keep at it and keep you posted. Unfortunately I don’t have a timeframe for when I would get something done. I’ll post here though when I do. :slight_smile:

To expand on Tim’s post.

  1. Make sure the “Static Mesh” component has “Simulate Physics” set to “True” (checked).

  2. Make sure the “Physics Thruster” component is a child of the “Static Mesh” component.

  3. Make sure the “Physics Thruster” component has “Auto Activate” set to “True” (checked) for testing purposes. That way, you don’t need to worry about Blueprint logic until the desired outcome is achieved.

  4. Make sure the “Collision Shape” for the “Static Mesh” component isn’t intersecting with another actor when you place it into the scene.

So, a few considerations to make the Blueprint behave like an actual soda. “Simulate Physics” should always be “True” on the “Static Mesh” component so that other actors can interact with it. The “Particle” and “Physics Thruster” components should be set to inactive until an event (such as a “Line Trace”) is executed, then made active (to give the illusion of the soda leaking), then made inactive again after a delay. This should be done within a “DoOnce” loop, unless you want a magical soda that refills itself.

With all of the above being said, here is how I set up the Blueprint.

http://i.imgur.com/zK04DLQ.png

http://i.imgur.com/jcbYiux.png

http://i.imgur.com/6klGvY6.png

http://i.imgur.com/w6s1wNa.png

http://i.imgur.com/PXgPdWM.png

I hope this helps!

Finally, [here is a video of the result][6].

I have to admit I am quite a novice when it comes to UE4 blueprints, if you have the means to record a tutorial for this then that would be much appreciated. Thanks

It (a tutorial) is something I’d like to get around to eventually, but I’m confident that if you follow along with the Blueprints above, you’ll achieve the same result. If you need further assistance, please let me know.

It ok I’m just having problems finding some of the nodes such as the SET node

The “Set” node is only available after you’ve created the variable. You can access it under “Variables” in the right-click menu, or on the left side of the “Graph” window by holding “Alt” and then dragging the variable into the “Event Graph”. If you’re unsure about how to create, get, and set variables, I’d recommend watching this video, this video, and this video.

Those videos were very helpful, thank you

Ok I really hate to be a pest but I have no idea how to get the Target Hit Actor node. I really am a complete novice :stuck_out_tongue: