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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
1
Question by OVillanueva · Dec 24, 2014 at 10:22 PM · swaystacking

Stacked Objects Swaying: Is there a script for this?

Basically, I would like to create this type of movement with the stacking game I'm creating. Is there a script I can use to pull this off?

https://www.youtube.com/watch?v=CvSu53CjUl8

Watch how the tower blox stack and then begin swaying as the tower becomes taller.

Comment
Add comment · Show 4
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 HYPERSAVV · Dec 25, 2014 at 01:32 AM 0
Share

Judging by the action made at 0:39, this is just using "fake" physics. Objects in the stack can be made $$anonymous$$inematic as they land, with the platform below them rotating slightly from side to side (after a certain amount of items have been added).

avatar image OVillanueva · Dec 25, 2014 at 11:52 PM 0
Share

Thank you for your reply.

I'll send this comment to my programmer and see if he can execute what you've mentioned.

avatar image OVillanueva · Jan 02, 2015 at 06:26 AM 0
Share
  1. The blocks in question are actually cakes that come in three sizes. They have a box collider only as my engineer said he rather we program the actions ins$$anonymous$$d of using physics. I believe he doesn't use Unity's gravity feature, rather he has some kind of velocity control.

  2. For the size, see the screenshot: http://puu.sh/dXsSP/10ac68c25c.png

  3. In terms of the number of cakes shown, around 10-15, including the one held by the character.

  4. For the camera view, it is similar to Tower Bloxx. Basically my game follows the visual conventions of Tower Bloxx.

avatar image jpthek9 · Jan 03, 2015 at 06:53 PM 0
Share

Just edited my answer with something that should work. If you need something more like calculating the horizontal offset of the two cakes and checking that against the $$anonymous$$imum you supply (i.e. >50% means it tips over) just take Direction.x and check that against Colider.bounds.extents.x.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by jpthek9 · Dec 26, 2014 at 12:33 AM

Copy paste this script into a C# file named 'SwayScript'. Cleaned it up in Mono so it looks nice and formatted now :)

 using UnityEngine;
 using System.Collections;
 
 public class SwayScript : MonoBehaviour {
     public static int TotalStacked;
     public float SwaySpeed;
     public float MaxAngle; //In degrees
     public int Swayer; //This is for finding the first cake off camera (I.e. if you display 5 cakes, set this to 6)
     int StackPlacement;
     bool RotateRight;
     void FixedUpdate()
     {
         if (StackPlacement == TotalStacked - Swayer)
         {
             if (RotateRight)
             {
                 transform.Rotate (Vector3.right * SwaySpeed * Time.fixedDeltaTime);
             }
             else{
                 transform.Rotate (-Vector3.right * SwaySpeed * Time.fixedDeltaTime);
             }
             if (Mathf.Abs(transform.eulerAngles.x) > 30)
             {
                 RotateRight = !RotateRight;
             }
         }
     }
     bool Sticked;
     void OnTriggerEnter(Collider col)
     {
         if (Collider.gameObject.tag == gameObject.tag)
         {
             if (!Sticked)
             {
                 Vector3 Direction = transform.position - Collider.transform.position;
                 
                 if (Direction.y < (Collider.bounds.extents.y + collider.bounds.extents.y))
                 {
                     return;
                 }
                 else{
                     transform.parent = Collider.transform;
                     Sticked = true;
                     TotalStacked++;
                     StackPlacement = TotalStacked;
                 }
             }
         }
     }
 }


Comment
Add comment · Show 10 · 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 OVillanueva · Jan 02, 2015 at 01:58 AM 0
Share

So it looks like i have to wait a while before my engineer can even help me with this project, again. Is there a script I can use to get this working? I'd like to try this on a separate computer with Unity installed and see if I can get it working myself.

Cheers

avatar image jpthek9 · Jan 02, 2015 at 03:33 AM 0
Share

I'll write you up something but I'll need more details. 1. How do the blocks stack (i.e. like in the video with the gravity based drops), 2. How big are the blocks, and 3. How many blocks are you expecting? Oh yeah, and what will the camera view be like (I.e. the top part of the tower only)?

avatar image OVillanueva · Jan 05, 2015 at 12:08 AM 0
Share

Thanks for providing this. I plugged your code in but the other code that's present within the build is conflicting with this new one. I'm not quite sure how to fix this. I'll send you P$$anonymous$$.

avatar image jpthek9 · Jan 05, 2015 at 01:18 AM 0
Share

Hmm not sure how to use the message system on Answers. Guess now's a good time as any to learn. One solution that might work is to copy-paste the code into a new script and you just have a seperate one managing sway and attachment.

avatar image OVillanueva · Jan 05, 2015 at 10:31 AM 0
Share

I did create a separate C# file and pasted your code there. This is the result: http://puu.sh/e5i0R/e97f8414e9.png

This is how I pasted the code into $$anonymous$$ono: http://puu.sh/e5ifX/d7e7c46134.png

avatar image Scribe OVillanueva · Jan 05, 2015 at 10:36 AM 0
Share

put the code inside your $$anonymous$$onoBehaviour class, basically everything except library imports needs to be inside a class of some type.

Show more comments
avatar image
0

Answer by gzrjzcx · May 30, 2019 at 06:20 PM

Hi, have u finished this project? I am making the similar game, and I am also struggling for the swinging effect of stacked pieces. Do u have any advise?

Comment
Add comment · 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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How to import the object from server to unity 2 Answers

Setting Scroll View Width GUILayout 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Material doesn't have a color property '_Color' 4 Answers


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