- Home /
Parent transform forward as reference then need to ADD Torque to that
I am having trouble wrapping my head around a solution for this.
I am attempting to add torque to a sphere using the direction of its parent (camera) as the starting point. My trouble has been trying to add the torque vector to the vector forward of the cameras transform. I know this is easier than I'm making it.
My code is a mess from too many edits... If anyone has a code snippet in C#, I would be eternally grateful!
Thanks ahead of time! Answers is awesome!
LOL, no I'm not a physicist, nor am I a rocket scientist, but I am familiar with the ter$$anonymous$$ology, etc. Thank you for clarifying, one never knows who's on the other side.
Lemme fill in some details to shed some light on my specific application.
I created a "roller controller where torque is the sole driving force of movement. ( I must say its fun as heck to play with lol) I currently have 3 ways to control the sphere:
Right mouse to orbit camera around sphere... At any time...
WASD ( adds appropriate torque relative to view
Left mouse button down and held while the right button is also held gives simple torque in direction of view (camera)
Click and drag left mouse button - creates a user defined direction to spin the sphere. The mouse down sets point1 and point2 is sampled every frame on update. So the torque vector is created from the updated mouse position relative to stationary point1.
The strength of the torque applied is dictated by the distance ffrom point1
I.e. torque is applied in the direction mouse has been dragged and magnitude is how far they have dragged from where they clicked.
The third one works beautifully ( and I almost had a party when I got it working right) but as long as the camera hasn't been rotated! To be useful, it needs to be relative to the view direction like the first two methods.
So with the explanation, does the camera need to be parented, or can it be independent, AND how will that help with view control? Also it is nice to just grab the parent and move it around.....
BTW thank you for taking the time to help! I truly appreciate it!
Here's a link to my original post
http://answers.unity3d.com/questions/294451/making-a-torque-based-sphere-controller-by-simple.html
Answer by aldonaletto · Sep 13, 2012 at 05:30 AM
Well, you could try something like this:
rigidbody.AddTorque(transform.parent.forward * someTorqueValue);
But be aware that rigidbodies are wild! They rarely do what you expect without doing lots of annoying unexpected things. The instruction above, for instance, will make the object rotate around weird axes during some time before finally settling down to the desired rotation, and any parent rotation will start another disappointing weird sequence. Parent movements also aren't immediately followed by the child rigidbody, which will move exasperating slowly in the movement direction - not to mention other movements in unexpected directions that will result from this.
If you simply want to rotate an object around the camera's forward direction, avoid rigidbodies and simply use Rotate - like this:
public float rotSpeed = 360;
void Update(){ transform.Rotate(0, 0, rotSpeed * Time.deltaTime); } This code rotates the object around its forward direction. If the object's initial localRotation is Quaternion.Identity (Rotation field = 0,0,0 in the Inspector), it will rotate always around the parent forward direction, no matter to which direction the parent is turned to.
Actually, I've experienced beautiful results upwards and above angular velocities of 200+ lol !
Really fun to skid out with a sphere and jump ramps..... I'll post a link when I have a fully working scene.
Thanks for the code the first snippet may just help
Thanks for the insights on this! $$anonymous$$uch appreciated! I imagine I havent yet experienced these types of issues because Ive only been doing noob stuff, lol thanks again!
Answer by I9ball · Sep 18, 2012 at 09:48 PM
Thanks for the explanation! Sorry about the large bold text in the previous comment, :p.
Got it. So then we would simply use scripting to follow an object with a cam and similar instances?
sorry took so long for the tick.... internet has been troublesome. thanks for the great responses everyone!
Your answer
Follow this Question
Related Questions
SImply yet tricky question about RELATIVE VELOCITIES... 1 Answer
gui position of Screen relative position 2 Answers
Relative Accelerometer Movement 0 Answers
Place object relative to player location 1 Answer
Reletive rotation problems. (C#) 2 Answers