# Making a torque-based sphere controller by simple mouse inputs

 0 I'm new to C# and Unity but progressing quickly. I have been able to get most of it under control but this is taking too much time so... I'm throwing up the help Flag :)The idea is the player will control a Sphere in a Roller style game via mouse.Mouse Control: starts with left mouse Press. Records first Point. A GUI helper will appear on that point as visual feedback for input. Player Drags mouse from start point. Vectors are created on the fly using the angle and distance from the center translates as magnitude (and hopefully speed of the force applied) of the UI drawn vector for imparting that exact vector force on the sphere. The player should be able to command torque from this UI in any direction and most velocities easily and on demand.So, the trouble comes in a number of ways so far. The first is: how do I create the corresponding torque in ALL directions? I I have managed to create a prototype that works "half-way" but it wont perform correctly in some quadrants. multipliers were giving me grief in this area as well.I tried to pull back from the purist approach above and try some alternatives thinking i could run the torque along the X axis like a wheel and just try to "Steer" or rotate it as needed.... nope that was a mess.my code has been altered and tweaked so many times, but I was able to scrape out my original code below. I apologize now for inefficient or bad coding :) I'm a designer who likes to dig in...(code)Initial Code attempt: Drop onto sphereusing UnityEngine; using System.Collections;public class addTorque : MonoBehaviour { private Vector3 spinVector;void Update() {if (Input.GetMouseButton(0)) { float vectValueX = (Input.GetAxis("Mouse X")) * spinVector.magnitude; float vectValueY = (Input.GetAxis("Mouse Y")) * spinVector.magnitude; rigidbody.AddTorque(vectValueX, 0 , vectValueY); } }}Appreciate any help I can get! I look forward to your replies :)-Paul rolleruiscreenshot.jpg (44.8 kB) more ▼ asked Aug 01 '12 at 08:37 PM I9ball 130 ● 1 ● 5 ● 10 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 I was my own worst enemy in this case. I used code from too many iterations of my experimentation to rebuild my first attempt.Well here is the correct code This code works as expected for a milestone. Multiplier and the UI are the next stage.Thanks ```using UnityEngine; using System.Collections; public class torqueController : MonoBehaviour { private Vector3 startPoint; private Vector3 endPoint; private Vector3 driveDirection; void Update() { if(Input.GetButtonDown("Fire1")) { startPoint = Input.mousePosition; } if (Input.GetMouseButton(0)) { endPoint = Input.mousePosition; driveDirection = endPoint - startPoint; rigidbody.AddTorque(driveDirection.x, 0, driveDirection.y ); } } } ``` `````` more ▼ answered Aug 02 '12 at 11:24 PM I9ball 130 ● 1 ● 5 ● 10 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
 0 Can Someone please select my previous post as the answer to this question :) wont lemme do it :/thanks more ▼ answered Aug 02 '12 at 11:26 PM I9ball 130 ● 1 ● 5 ● 10 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x986
x580
x526
x199
x1

asked: Aug 01 '12 at 08:37 PM

Seen: 413 times

Last Updated: Aug 04 '12 at 01:38 AM