# playMaker

### Author Topic: Flipping a Coin with Physics [SOLVED]  (Read 2297 times)

#### acornbringer

• Junior Playmaker
• Posts: 68
##### Flipping a Coin with Physics [SOLVED]
« on: January 17, 2019, 06:21:45 PM »
I re-made my old dice roller app and added in all the standard RPG dice and included a coin for "d2" rolls.

All the dice are fine with just being flung into the scene with a random rotation set and having the physics take care of the rest like a real roll of the dice. However a coin needs more of a flip effect that I can't figure out using the Playmaker actions.

What I have tried which kind of works is using the "Add Torque" action when the coin is created. I give it some torque to spin on the X axis as if it had been flipped into the air but no matter how high I set the value, I never get a satisfying speed with the rotation. It seems to cap out at a kind of slow-mo spin.

I tried various other adjustments to the Rigidbody and Physics material but I can never get the coin to flip as fast as I would like. Is there something I'm missing?

Thanks
« Last Edit: January 21, 2019, 06:06:15 AM by acornbringer »

#### craigz

• Beta Group
• Full Member
• Posts: 218
##### Re: Flipping a Coin with Physics
« Reply #1 on: January 18, 2019, 12:22:07 AM »
Hi acornbringer!

I've actually made a coin flipping game before and I tried a few different things that worked well

1.
Apply an impulse force along the world Y axis, and in that same action put a wait for about .3 seconds or so? Just enough for it to be up in the air THEN have it go to a state that applies the torque impulse like you're currently doing that should do the trick.

2.
The other way to do this that's less physics heavy but also looks fun (and is maybe more the style you might be going for). Is to apply an impulse force along the Y like the previous step with a wait, but then in the next state use an random float action, and generate a float between 400-1800 or so? Then use a Set Vector XYZ action to a vector3, and plug that into an iTween Rotate Add action or similar to rotate the coin a random amount while it's in the air. This is definitely less physics looking, but has a good snappiness to it I think I forgot in the GIF, but you can either use the time OR the speed depending on the look you're going for xP

**random notes
As I'm sure you know from the dice you've made, there's a bunch of ways to add some fun little randomness to the flip too like height it starts from, force applied up as well as spun etc. Always nice

-craigz

#### acornbringer

• Junior Playmaker
• Posts: 68
##### Re: Flipping a Coin with Physics
« Reply #2 on: January 18, 2019, 01:10:27 PM »
Hi acornbringer!

I've actually made a coin flipping game before and I tried a few different things that worked well

[...]

Hey craigz!

Thanks for the in-depth explanation. It's fortunate you made a coin flipping thing once too!

I'm able to get an okay flip out of this technique but I'm looking for more zip. Unfortunately, no-mater how much torque I apply it never increases in spin speed.

The effect I'm looking for is more like someone flipped the coin up with their thumb and made it spin pretty quickly before catching it again. Are you able to get a faster spin than what I'm seeing?

Thanks

#### craigz

• Beta Group
• Full Member
• Posts: 218
##### Re: Flipping a Coin with Physics
« Reply #3 on: January 20, 2019, 04:25:20 AM »
Ahhh!

That looks super solid! literally exactly the setup/look I had before.

Yeah, so option number 2, using tweening will look a LOT more snappy, especially if you use something like Quad out etc.

But if you want to go all physics, you could totally try out animating a float value (with Curve Float action and some nice curves?) and then assigning that to an add torque action set to maybe acceleration or velocity change instead of impulse?

#### acornbringer

• Junior Playmaker
• Posts: 68
##### Re: Flipping a Coin with Physics
« Reply #4 on: January 20, 2019, 03:35:58 PM »
Hi again Craigz!

I gave your suggestion a try but was unfortunately unable to get any different results. The torque just won't get the coin spinning as quick as I would like.

Having the solution be all physics would be simpler for sure but I'll definitely see what I can do with tween animation.

It's really all about the feel I'm after so it don't matter too much if it's animated or physics at the end of the day.

#### craigz

• Beta Group
• Full Member
• Posts: 218
##### Re: Flipping a Coin with Physics
« Reply #5 on: January 20, 2019, 10:31:10 PM »
hmm... maybe instead of torque you use that animated float and just plug it into a rotate action with every frame, per second and fixed checked?

#### djaydino

• Hero Member
• Posts: 6484
##### Re: Flipping a Coin with Physics
« Reply #6 on: January 21, 2019, 12:45:03 AM »
Hi.
There is an action on the Ecosystem called : RigidBodySetMaxAngularVelocity

With this you can adjust the limitation.
Here i a link to the unity documentation :
https://docs.unity3d.com/ScriptReference/Rigidbody-maxAngularVelocity.html

Ecosystem might not work at the moment
here are direct Github Links to the custom actions :
https://github.com/PlayMakerEcosystem
https://github.com/jeanfabre

Join the PlayMaker Discord Channel!

#### acornbringer

• Junior Playmaker
• Posts: 68
##### Re: Flipping a Coin with Physics
« Reply #7 on: January 21, 2019, 06:05:08 AM »
Hi.
There is an action on the Ecosystem called : RigidBodySetMaxAngularVelocity

[...]

Hey look at that! Works really well

Thanks for pointing that property out. It's not exposed in the inspector or anything so I don't think I would have ever found it.

I think I'm good to go with this. I appreciate the help from both of you! I definitely learned a bit more about physics from this.

#### djaydino

• Hero Member
• Posts: 6484
##### Re: Flipping a Coin with Physics [SOLVED]
« Reply #8 on: January 22, 2019, 02:25:33 AM »
Hi.
Before you do.
Do some performance tests, just to be sure
Ecosystem might not work at the moment
here are direct Github Links to the custom actions :
https://github.com/PlayMakerEcosystem
https://github.com/jeanfabre

Join the PlayMaker Discord Channel!

#### acornbringer

• Junior Playmaker
• Posts: 68
##### Re: Flipping a Coin with Physics [SOLVED]
« Reply #9 on: January 22, 2019, 10:39:46 AM »
[...]
Do some performance tests, just to be sure

I'm not super familiar with the profiler in the editor but I ran it a few times with and without some components and it didn't seem to change that much while I scanned through the different physics elements. The build also works the same as always.

If you would like to, you can try it out to see how it's doing

https://acornbringer.itch.io/pocket-bite-d20

Thanks again!

#### djaydino

• Hero Member
• Posts: 6484
##### Re: Flipping a Coin with Physics [SOLVED]
« Reply #10 on: January 22, 2019, 12:22:22 PM »
Hi.
Nice app,
are you planning to make a mobile version?
Ecosystem might not work at the moment
here are direct Github Links to the custom actions :
https://github.com/PlayMakerEcosystem
https://github.com/jeanfabre

Join the PlayMaker Discord Channel!

#### acornbringer

• Junior Playmaker
• Posts: 68
##### Re: Flipping a Coin with Physics [SOLVED]
« Reply #11 on: January 22, 2019, 12:29:55 PM »
Thanks!

Yeah, I want to make it work for android as well but I won't get my android phone to test on for a few more weeks.

Meanwhile I'll look into how Playmaker does touch screen stuff so I can set that up once I have the phone.

#### Croesus

• Playmaker Newbie
• Posts: 7
##### Re: Flipping a Coin with Physics
« Reply #12 on: July 26, 2021, 02:34:43 PM »
Hi.
There is an action on the Ecosystem called : RigidBodySetMaxAngularVelocity

[...]

Hey look at that! Works really well

Thanks for pointing that property out. It's not exposed in the inspector or anything so I don't think I would have ever found it.

I think I'm good to go with this. I appreciate the help from both of you! I definitely learned a bit more about physics from this.

Hello. Can you share the FSM for this spinning coins?