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 AlucardJay · Mar 21, 2012 at 05:06 AM · rotationpositiontorquefacing

rotating to the current facing position

I am trying to write a script for a hover board.

The problem I'm having is rotating the board to the position the player is facing, and ,

(the board is hovering so there is no drag) moving the board in the correct direction.

Currently the character turns but not to the direction of travel.

 var moveX : float = 0.0;
 var turnForce : float = 10.0;
 
 function Update () {    
     moveX = Input.GetAxis ("Horizontal");
     rigidbody.AddTorque(Vector3.up * (moveX * turnForce * Time.deltaTime));
     // turning but 'sliding' , add relative force to 'push' in new direction
     rigidbody.AddRelativeForce(Vector3.right * (moveX * turnForce * Time.deltaTime));
 }

Even if I make a vector which I want the object to face, I don't know how to rotate or add torque to face that point.

(this is more of a general comment rather than a question) :

I'm having great difficulty understanding how to rotate my characters in any scripts, with either method (transform or rigidbody).

I just cannot get my head around local space and world space in relation to any of the transform rotation Quaternian Slerp stuff, or the physics rigidbody addTorque stuff.

here is the project : http://www.alucardj.net16.net/unityquestions/hoverboard%201-1a.html

here is the full script : http://www.alucardj.net16.net/unityquestions/ScriptHover1-1a.js

(note: the textures and objects are basic =] , I am just using them to write the script , and for now the rigidbody constraints are on for rotation X and Z)

Comment
Add comment · Show 5
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 AlucardJay · Mar 21, 2012 at 03:58 PM 0
Share

So I guess the short version of this question would be : how do I turn a rigidbody using torque , to turn and face a certain vector , then stop ?

avatar image AlucardJay · Mar 22, 2012 at 01:05 AM 0
Share

I have seen a few questions on this 'site appear after I asked this with rotation problems. Is this area equivalent to the 'dark arts' , or is it a case of 'if you don't know and can't figure it out I'm not telling you'. I have seen some smart cookies on this 'site so I am surprised there is no link to a previous decent explanation on : How to rotate a rigid body with addTorque to a specific angle , then stop. : How to rotate a gameObject with transform.rotate to a specific angle , then stop. This is co$$anonymous$$g across as whiny, sry but am just desparate for that 'ahhh' moment when understanding how to rotate objects falls into place. $$anonymous$$any thanks to the smart cookies on this 'site, I have learned alot just by reading through the questions daily :)

avatar image DaveA · Mar 22, 2012 at 01:44 AM 0
Share

Do you really want to do this with physics (torque) or do you want it to just follow the player?

avatar image AlucardJay · Mar 22, 2012 at 01:58 AM 0
Share

this question is for the Player. I am using a rigidbody for the player so using torque to rotate to angle, then stop turning , so yes please !

I would like to know the transform.rotation method for gameObjects withOut rigidbody's also, but for now and this project, rigidbody and force/torque .

avatar image AlucardJay · Mar 22, 2012 at 02:03 AM 0
Share

this qn is the movement and player rotation component to a bigger project : http://answers.unity3d.com/questions/230216/why-am-i-getting-a-fruity-effect-from-my-raycast.html the webplayer publish on this shows the Player moving on it's own to match the board angle to the terrain angle. This question adds Player input to movement.

2 Replies

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

Answer by AlucardJay · Apr 15, 2012 at 08:12 AM

I have sorted the issues related to this old question. The problem I was having was understanding the difference between a transform.right and a Vector3.right

http://unity3d.com/support/documentation/ScriptReference/Vector3-right.html

http://unity3d.com/support/documentation/ScriptReference/Transform-right.html

But the actual issue was more to do with Controlling the rotation accurately using Force and Torque.

Quaternion in general remains a mystery : http://answers.unity3d.com/questions/230505/am-i-using-degrees-radians-rotation-or-quaternion-.html

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
avatar image
0

Answer by DaveA · Mar 22, 2012 at 02:05 AM

Why not just set the transform of the board to match the player? Something like (script on the hover board):

 function Update()
 {
   transform.rotation = player.transform.rotation;
 }

Move the board by, for example,

 transform.Translate (transform.forward * speed * Time.deltaTime);

With physics (untested)

 rigidbody.MoveRotation(player.transform.rotation);
Comment
Add comment · Show 3 · 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 AlucardJay · Mar 22, 2012 at 02:22 AM 0
Share

thanks, that shows me a command that can rotate over time to an angle. I shall play with that in some test scripts.

$$anonymous$$y basic understanding was : to get real physics effect (colliding with other objects) I had to use rigidbody's , and manipulate them with force and torque in a FixedUpdate loop. Also using addForce And transform was wrong, and could lead to strange consequences with the physics engine.

I have come across a method using dot products, am trying to absorb and understand that (while answering a post and testing for another question. Lots of help today, much appreciated).

dot product info I am looking at : http://forum.unity3d.com/threads/31420-Left-Right-test-function . this doesn't answer my qn, more chooses a direction to rotate in.

avatar image DaveA · Mar 22, 2012 at 02:32 AM 1
Share

Yeah, I've heard that too, and a lot of people complain there are no apparent ways of tightly controlling when things stop etc. One way would be to hit Physics 101 text books and do the math (eeek). Another is to 'monitor' position and rotation and tweak it, analogous to firing 'retro rockets' to slow and stop things. Looking again at http://unity3d.com/support/documentation/ScriptReference/Rigidbody.$$anonymous$$oveRotation.html I think by 'friction' they mean it applies whatever forces are needed to achieve this rotation. So give that one a try. Editing answer to illustrate.

avatar image AlucardJay · Mar 22, 2012 at 03:01 AM 0
Share

while replying, just wanted to say thanks. and yes, with the board hovering and there being no drag, I do also need to add 'retro rockets' . That's what I was trying to achieve with the AddRelativeForce statement. Reading the script reference for $$anonymous$$oveRotation .

I found that $$anonymous$$oveRotation 'snaps' to the Quaternion it is given. So I tried to make a target var that is changed with the horizontal input axis over time, but it is giving strange results :

 var targetRotAngle : Quaternion = Quaternion.Euler (0, 0, 0);
 var turnSpeed : float = 10.0;
 
 function FixedUpdate () {    
     targetRotAngle = Quaternion.Euler (0, transform.eulerAngles.y, 0);
     targetRotAngle.y += Input.GetAxis("Horizontal") * Time.deltaTime * turnSpeed;    
     rigidbody.$$anonymous$$oveRotation(targetRotAngle);    
 }

I am messing up and getting more confused with Quaternian .rotation and euler angles .

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

[2D] Adding torque to rigidbody to look at point 0 Answers

2D Torque rotation - stop at certain angle 0 Answers

Instantiate VS placement in editor 0 Answers

Unfreezing rotation causes the position and rotation go crazy 0 Answers

Spwan and shoot bullet in direction of shooter? 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