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
0
Question by RHD · Dec 16, 2012 at 01:54 PM · rotation

Adding a 45º rotation to a script

I have this script below which moves a platform backwards and forwards. I would like to be able to add a rotation to it so that as the platform travels backwards and forwards it turns to face the way it is going. I've tried several things I found on Unity Answers but just get a whole bunch of errors even though I've been very careful to follow the syntax (as far as I can) Any help would be greatly appreciated, thank you. Here is the script I have that moves the platform:

 #pragma strict
 private var old_pos : Vector3;
 var move : boolean = false;
 var speed : float = 1;
 var time_shift : float = 0.0;
 var move_by : Vector3;
 
 function Start() {
     old_pos = transform.position;
     tag = "platform";
 }
        
 function LateUpdate () {
     if(move)
         transform.position = Vector3.Lerp(old_pos, old_pos + move_by, (Mathf.Sin((Time.time + time_shift) * speed) + 1) / 2);
     transform.eulerAngles = Vector3.zero;
 }
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 Statement · Dec 16, 2012 at 02:46 PM 0
Share

Welcome to Unity Answers. Please try and make sure that your code is readable or no one will take their time to answer it. I fixed the readability issues in your sample code but please ensure that it's reasonably readable for future questions. And good luck! :)

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Gruffy · Dec 18, 2012 at 09:31 PM

Hey RHD. So....I have built you a small grey box with a platform that can be rotated on the left mouse click, provided your cursor, in game, is placed on the platform. To stop it you have to hold the "m/M" key on your keyboard and again point at the platform and click the left mousebutton. I have added some suggestions in the code to (PlayerGameInput and Platform scripts) as to how to obtain a simple angular change from one to another or the other potential to rotate the platform a set angle a time. This is in the code, so please read that to see what i mean. So I havent fixed your problem for you, with respect to completely doing your job for you, in the nicest possible sense. Instead, I have provided you with a set of tools that can be used to complete your goal, but the caveat is that you must mould it, otherwise you may never get to a point where you can feel you could provide others with the help they need to understand all this Unity stuff. Hope that makes sense, as I mean it in the best possible light.

If the package has any issues, let me know, but all shoudl work well..... To clarify my warbled mess above....

Just import package in to unity(v.4) and click the scene, then play, point to platform, left click - to start rotation, hold "m" and left click to stop rotation.

Look at the code, I promise you could change it to exactly what you are looking for, I have already done so to make sure, so what I have said in the code should guide you enough to discover the right path to euphoric feeling of solving one problem to find another almost as quick :) Good luck RHD, let me know how it goes if you want. Gruffy :) Rotate Platform package


rotateplatform.zip (54.8 kB)
Comment
Add comment · Show 5 · 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 Gruffy · Dec 16, 2012 at 04:08 PM 0
Share

where do you set move to true ?, as a start :) In this nicest possible sense of course, I mean to try and sway ya brain a little, because if you think... you are asking your if to clarify if something is true, and its last known status is where you have initiallised it to false up the top. Think about how you might get that to change by taking in some input that accesses your boolean and changes it to true. Hope that helps in some small way Gruffy :)

avatar image RHD · Dec 18, 2012 at 09:59 PM 0
Share

Gruffy, man! Thank you for the package! I can't believe you went to all that trouble, that's really, really great of you! I'm still on Unity 3.something though and can't open it at the moment! Please don't worry about it, I'll upgrade very shortly and try it out. Thank you so SO much man for all your help! If I get the whole thing working in the end I'd like to send you a copy. Cheers!

avatar image Gruffy · Dec 19, 2012 at 11:32 AM 0
Share

Hey RHD, no worries bud..Tis a shame 3 is stopping you though If you go to Unity website, you can download Unity4 community edition - tis free for releases not exceeding a profit of 50,000 which is pretty good and no different from 3 in that respect, plus some nice features that 3 was lacking and bugging out over(another topic though that). Even if you wanted to stay in 3 you could download the unity 4 installer and install to another folder or disk partition and you should still have both, dont quote me on that though but, all you old projects get converted to 4 anyway so its a bit of a NOBRAINER, in the nicest possible sense as always, and really it would be to your credit. DO IT RHD, you will not regret it + you will then have a working platform scenario in the right environment. If not, just unzip the package with a rar, 7zip, winzip software and extract the scripts out of the package, the code is still viable as is just c# and familiar Unity engine requirements. Please get Unity4 you ar emissing out for zero reason I wager. take care RHD, I wouls still ove to see what you do with it , if anything but thats up to you big boi! If you really thought the answer was helpful, could I ask that you select a thumbs up for the answer i gave so others looking for a similar answer may find it and benefit too(important, it stops people asking the same questions over and over). Thanks bud DO IT DO IT DO IT DO IT :) (unless there is some unfathomable reason why not of course ( Rhetoric:is fathomable even a word?)) Gruffy :)

avatar image RHD · Dec 19, 2012 at 08:50 PM 0
Share

No way I'm upgrading to 4 in the middle of a project. I went from 2.6 to 3 in the middle of a project last time and so many scripts and shaders and things broke and I had no idea how to fix them, I ended up abandoning months of work. It was just heartbreaking.

avatar image Gruffy · Jan 01, 2013 at 03:35 PM 0
Share

fair does bud, i feel ya pain

avatar image
0

Answer by Gruffy · Dec 16, 2012 at 06:07 PM

Hey RHD. Right if you go to the script and try to find what the y value and speed are represented as, you should be able to represent them outside of any fucntion publically in js or declare them public "data type(being float,int etc)" your_var_name

Im not hot on the js semantics im afraid, but you could easily look up how to get your var into the Object inspector. As for c# this is how below

 public float myYRotationScale = 0;
 public float speed = 10;
 
 //these can then be changed in the inspector at your whim.

If you post your script, I & others can see it and maybe point you to the right areas to change/addend or even quickly do it for you. Cheers bud, hope it all makes some sort of sense :) Gruffy

Comment
Add comment · Show 13 · 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 RHD · Dec 17, 2012 at 12:46 AM 0
Share

Eric5h5 and Statement. Thank you. Trying to use this answers setup seems to be more full of pitfalls than trying to learn to code in Unity and considerably more pointless. If you could all stop complaining that I'm posting things wrong (and WHY does it have to be a learning curve just to post a question?) and actually try and help me I would feel a lot better about all the money I've spent on Unity. Including the version 4 Update I bought in July and of which there is still no news now at Christmas.

Thank you.

avatar image RHD · Dec 17, 2012 at 12:49 AM 0
Share

Gruffy, sorry that comment wasn't for you. Thank you for your continued help, this looks helpful and is something I can understand and is along the lines of things I have tried.

The problem is my public variables are not showing up at all in the Inspector when assigned. I'm having the same issue with another script. Thanks

avatar image Eric5h5 · Dec 17, 2012 at 01:07 AM 0
Share

@RHD: it makes this site harder to use for others if it's not used correctly. It's not a forum; for that, there's forum.unity3d.com. UnityAnswers is like StackOverflow, but for Unity...it's a Q&A format rather than a discussion format.

Not quite sure what you mean about "Including the version 4 Update I bought in July and of which there is still no news now at Christmas" since Unity 4 was officially released a while ago and public betas have been available for months. There has been a great deal of news about Unity 4, or is there something in particular you're looking for?

avatar image Statement · Dec 17, 2012 at 01:08 AM 0
Share

Trying to use this answers setup seems to be more full of pitfalls than trying to learn to code in Unity...

I tried to give you a tip in my welcome that unformatted code often shuns people away from even trying, and helped you correct the post so you would get some nice replies.

If you could all stop complaining...

I noticed that there seems to be something acting up with Answers as of lately, so I fully understand that you might have formatted the code clearly, but that something messed up after you hit reply. I just had this happen to me a moment ago and I instantly understood this was what happened to you. I certainly didn't mean to tell you off at all in any way, but we have had a lot of people in the past who pasted unreadable code and no one ever bothered to help them. So I figured I'd share the tip for a newcomer that help is best received when people actually can understand what you need help with. I'll contact dZone who manages the Answers website tomorrow when I get in office about this problem.

It appears to be tabs that cause code to get formatting errors, so please try and convert tabs into spaces before posting and it should work better.

avatar image RHD · Dec 17, 2012 at 01:14 AM 0
Share

Eric5h5 well since I paid a lot of money an email to tell me to come and get it would have been nice. Just a little one.

Statement, you told me I was doing it wrong, you didn't explain how to do it right. I did try the format button on another question after you wrote to me but it didn't look to me like it did anything. I will try and follow the rules here but so far I've never really got anywhere with the Answers thing and think probably I should go back to the forum.

I suppose there's no way you can actually explain why my public variables aren't showing up in the Inspector? I've never had this before and have no clue what is causing it. Signing off for tonight though, it's gone 1am here. Thanks.

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

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

Help to figure a logic to achieve a movement. 2 Answers

Basic quaternion question 1 Answer

Rotating An Object On Its Axis Once 3 Answers

rotating an object only on z-axis help - c# 2 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