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 kraemer88 · Mar 05, 2011 at 12:02 PM · rotatemovesphere

Rotate and move the sphere while the up key is pressed

I'm kinda new to unity scripting and i can't manage to make my ball rotate and in the same time moving while the up button is pressed. My code attached to the sphere looks like this but unfortunately is not rotating the ball:

//Moving around and jump private var moveDirection : Vector3 = Vector3.zero; var speed : float = 6.0; var jumpSpeed : float = 8.0; var gravity : float = 20.0; //Rotate the ball while moving private var thisObj : Transform; var rotSpeed = 10.0;

function Start() { // Cachhe the transform link` thisObj = this.transform; } function Update() { var controller : CharacterController = GetComponent(CharacterController); if (controller.isGrounded){ moveDirection = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); moveDirection = transform.TransformDirection(moveDirection); moveDirection *= speed; } if (Input.GetButton ("Jump")) { moveDirection.y = jumpSpeed; }

// Apply gravity moveDirection.y -= gravity Time.deltaTime; // Move the controller controller.Move(moveDirection Time.deltaTime); transform.LookAt(target);}

function LateUpdate() { if (Input.GetButton("up")) { thisObj.Rotate(0, Time.deltaTime*rotSpeed, 0, Space.World); } }

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

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by AngryOldMan · Mar 05, 2011 at 02:42 PM

stick these variables in (adjust as necessary)

var TurnSpeed : float = 50;

put this under the starndard update function under if controller is grounded.(change the axis after eulerAngles if it's not the right rotation)

transform.eulerAngles.x += Input.GetButton("up")*(Time.deltaTime*TurnSpeed)
Comment
Add comment · Show 7 · 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 kraemer88 · Mar 08, 2011 at 06:26 PM 0
Share

This may sound noobish, but the compiler give me an error which i wasn't able to solve it.

Operator '*' cannot be used with a left hand side of type 'boolean' and a right hand side of type 'float'.

avatar image AngryOldMan · Mar 09, 2011 at 03:49 AM 0
Share

what line specifically? can u type it please, cant be sure that me counting your post will still be accurate.

avatar image kraemer88 · Mar 09, 2011 at 01:51 PM 0
Share

At the solution provided by you.

Input.GetButton("up")*(Time.deltaTime*TurnSpeed)

avatar image AngryOldMan · Mar 09, 2011 at 03:03 PM 0
Share

ah yeah my bad. Input.GetAxis is what u need not Input.GetButton.

avatar image kraemer88 · Mar 10, 2011 at 02:18 PM 0
Share

Well, this looks like this solve's the problem, but after a while the ball stops from movement and rotation too. Some kind of loop will solve the issue?

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

No one has followed this question yet.

Related Questions

Making a sphere move and rotate like a real ball on ground 2 Answers

Rotate multiple objects around or rather move them on the surface of another object 1 Answer

Rotating Player 0 Answers

rotation snap, or any kinda snap 3 Answers

Why am I getting 2 different results with RotateAround? Trying to move cubes on surface of sphere. 0 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