Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by RielFox · Oct 23, 2016 at 09:08 AM · c#rotationscripting problemtranslateplatform

Way to make GameObjects rotate smoothly in turns - C# scripts behaves unexpectedly and no console error messages

Hello there,

Thanks for checking out my post. Firstly, I have two problems with my scripts, and I am not sure if I should have made a separate post for each one.

I'd also like to say that I am very new to Unity and, also, still trying to get the hang of C#, so my code will most probably contain errors and there will definitely be a more clever/elegant and shorter way to write code that has exactly the same effect I wanted (if the code worked, that is). Any suggestions for improvements and optimization or more clever use for code are welcome, as I am always trying to improve.

Now, to get to the point, I am following an online course while trying to construct a small game for the assignment. The course has you develop a basic first-person game where you shoot spinning boxes, some give you score points and some give you bonus time. I followed the course videos to complete the first level, but for the second level I decided to add some unique elements to gain some more Unity experience.

I created an arena with 4 platforms and 4 aisles (roads), each connecting one of the bigger platforms, as shown below.

alt text


The first idea is that the aisles will move up and down in a wave-like motion, starting with the middle block (I have split the aisles into 9 platforms each, so the middle platform would be platform 5) and when the first platform reaches it's specified height, the platforms adjacent to it will start being elevated, elevating the middle platform as well to be an equal height above those adjacent platforms and so on..). In more specific terms, what I really want to do is for the aisle to ascend into a curve, and once it reaches its peak, descend until it becomes level. Then descend until it becomes a reverse curve and then, from there, ascend until it becomes level again. I want this behavior to loop during the game for all of my aisles.

The second idea is to select randomly (or in turns) every few seconds one of the big platforms which will flash red (change to a red material and back to the original a few times) as a warning and then rotate 360 degrees (smoothly but fast) , knocking the player standing on it down. (There will be a collider below the map which will catch the player and re spawn him - losing a life).

For reference, here is how I organized my platforms and aisles:

alt text

For the aisles, and after some experimentation, this is the closest I could come up by using two functions {I was thinking of using four functions as in AscentFromLevel(), DescentFromLevel(), DescentToLevel(), AscentToLevel() } but I tried to make it work only by using methods Ascend() to either open the curve, negatively or positively and Descend() to close the curve and bring it to a straight line (making it level).

Here's a segment of what the ascension would look like, from a segment of the code I managed to make it work: https://giphy.com/gifs/l3vRmjJf23JiF8xI4

The problem is that, there seems, as time passes, certain variables that were supposed to be constant start becoming bigger, thus the gaps between the platforms of the aisles become larger than intended (and un-scalable without a Jump function for the player).

This is the end result: https://giphy.com/gifs/l2JhOMBco8GCyylfW

And here's the code controlling the aisles, which will be a component of each of the 4 aisles:

http://pastebin.com/zCwfNnyV


The second objective was writing code that would choose one of the four platforms, every x amount of time, and rotate it 360 degrees once. I again experimented with the code a lot, and had an integer variable that can take values from 1 to 4 and flip the according platform using a rotate function on that platform. (The warning/flashing part is going to be similar code, so if I manage to do this, I can manage to do the warning bit as well). The problem is, whatever I do, the chooser will never increment, so the first platform will always be targeted. At first, platform0 would rotate indefinitely and, after changing the code to force the platform to rotate only once, will just rotate the first platform once, doing absolutely nothing afterwards.

Here is the code of the platform, which is attached as a component of Environment:

http://pastebin.com/DMx023yp


Thanks again and excuse my long post. I wanted to explain the situation as precisely as possible. Any advice is greatly appreciated!

unity1.png (65.9 kB)
jqjn-zwbeeartaqhdpgdfa-4c63d8c1efa505d2857e69424ab.png (190.9 kB)
Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

Flip over an object (smooth transition) 3 Answers

Temporarily turn off the relative rotation from parent in my script while keeping the relative position updated? 1 Answer

Rotate object around another object C# 2 Answers

HoloLens - Smooth Rotation doesn't work 0 Answers

How to translate object using 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