Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
-1
Question by sebbo1473 · May 03, 2013 at 08:33 PM · animationrotationframe

How to make One Arm Bandit?

Hello! Im currently busy with making kinda slot machine. I have a cilinder which has an animation where it rotates within 6 frames, each frame adds 60 degrees to the rotation and represents certain picture on the cilinder. What I want to do is to push one button to start spinning the disk (done) and another one to stop the spinning animation on a random frame. And it must be perfectly aligned in order to see the random result clearly. What is the best way to do so?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ExTheSea · May 03, 2013 at 09:18 PM 0
Share

http://forum.unity3d.com/threads/69371-How-would-YOU-make-a-slot-machine-%28$$anonymous$$oving-reels%29

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by robertbu · May 03, 2013 at 11:09 PM

Your question gave me a good excuse to play with animations which I've only used on a superficial level. Contrary to the many UA posts on pausing animations and setting the animation time, I was not able to freeze the animation on a specific time/frame. That is, the animation state reported the correct time, but the visual did not match. So here is a brute force solution of simply setting the rotation:

 var minSpinTime = 2.8;
 var maxSpinTime = 3.2;
 
 function Start() {
     animation["cylanim"].wrapMode = WrapMode.Loop;
 }
 
 function Update () {
     if (Input.GetKeyDown(KeyCode.Space)) {
         animation.Play();
         Invoke("StopWheel", Random.Range(minSpinTime, maxSpinTime));
     }
 }
 
 function StopWheel() {
     animation.Stop();
     transform.rotation = Quaternion.Euler(Random.Range(0,6) * 60.0, 0.0, 90.0);
 }
Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sebbo1473 · May 03, 2013 at 11:35 PM 0
Share

thank you for the answer! I tried this but it works not in correct way I believe. First is that the cilinder rotates in wrong axis. in my case it is placed along Z axis, and needs to spin in X, the animation makes it spinning from frame 0 till 6, rotating from 0 - 360 degrees - I placed it this way coz it looks like you are infront of the slot machine. Picture 1 - is how everything placed, and pic2 - play mode + space is pushed a few times. It just flips different axis and doesn't spin at all.. I am super noob, maybe yu have an idea?alt text

1_.jpg (32.8 kB)
2_.jpg (32.1 kB)
avatar image robertbu · May 04, 2013 at 02:06 AM 0
Share

All the "magic" is here:

 Quaternion.Euler(Random.Range(0,6) * 60.0, 0.0, 90.0)

Quaternion.Euler() takes three parameters for x, y, and z. So Let's assume that your wheel has a natural rotation of (0,0,0) (i.e. its base rotation before the button is pressed), and you want to rotate it around the 'Z' axis. You would need:

 Quaternion.Euler(0.0, 0.0, Random.Range(0,6) * 60.0);

You want the "Random.Range(0,6) * 60.0" for the axis you rotate around.

avatar image sebbo1473 · May 04, 2013 at 07:50 AM 0
Share

Hello again! I changed a few things and it works! But still with 1 problem. The code looks like that:

var $$anonymous$$SpinTime = 2.8;

var maxSpinTime = 3.2;

function Start()

{

//animation["spin"].wrap$$anonymous$$ode = Wrap$$anonymous$$ode.Loop;

}

function Update ()

{

 if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space)) 

 {

     animation.Play();

// Invoke("StopWheel", Random.Range($$anonymous$$SpinTime, maxSpinTime));

 }

 if(Input.Get$$anonymous$$eyDown("z"))

 {

     Invoke("StopWheel", Random.Range($$anonymous$$SpinTime, maxSpinTime));

 }

}

function StopWheel()

{ animation.Stop();

 transform.rotation = Quaternion.Euler(Random.Range(0,6) * 60.0, 0.0, 0.0);


}

I removed 90.0 degrees that u assigned for the Z axis, and I commented out the Invoke thingy and placed it under the condition of Z-button pressed. I want all this rotation stop after Z pressed. So it does! But! $$anonymous$$inor issue is that after I stop the spinning by pushing Z everything stops AND after 2-3 seconds it flips one more time (the same axis) to another frame, seems like. I believe the function StopWheel() works and stops everything but after that probably (Random.Range($$anonymous$$SpinTime, maxSpinTime)) makes it jump to another frame. So to say, very unnatural look. Another $$anonymous$$or issue is that the animation starts right after entering the play mode, not with pushing "space". Considering this issue data, can u conclude something logical? Very big thanks to you for the attention and help! $$anonymous$$ay be one day we will make it working! :D

avatar image sebbo1473 · May 04, 2013 at 11:19 AM 0
Share

Ok! I made it working! I changed a few things. In order to stop the animation I used just StopWheel(), without additional Random.Range. So I push Z now and it stops correctly placed with perfect angle. Nice. Thanks! But now I want to check which segment out of 6 is shown to front. So to say, what picture person sees infront of him. I have them 6 around the wheel, as angles/frames we used respectively. So what I am currently doing - I placed 6 empty objects on the wheel from side, each of them has only collider, and I figured out that rigid body is also necessary to attach. So, each of them is attached to certain color section on my wheel. I created another empty object "hook" with character controller and I am checking which one of those stops in the middle section and collides with the object+characterController. Every empty object from the wheel gives Debug.Log("current color name"). But the problem is that after the very first collision between "hook" and one of those 6 objects it seems cannot overwrite the console to another debug.log, from different collision, that goes after next spin. So that is strange for me. Coz all my barely solid concept depends from it. If I can't check which image is shown after stop, I can assign any winning condition. And I surely will have 3 wheels and all the outcomes of each spin out of each wheel.

avatar image robertbu · May 04, 2013 at 01:44 PM 1
Share

Is your code stopping randomly on one of the six sides or are you getting the same side each time? There are a list of ways to make this happen, but I can't think of a simple one (and I don't have time for an extended answer until this evening). Since this is a new question/issue consider opening it as a new question.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Lerping smoothly between animation and new position 2 Answers

Rotation Y axis is bugged. 2 Answers

Type of 3D Rotation Animation used in this video 1 Answer

Make the player go into the direction I am looking at 0 Answers

Animation in Unity editor prevents rotation in script 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges