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 I9ball · Aug 01, 2012 at 08:37 PM · vector3mousecontrollersphere

Making a torque-based sphere controller by simple mouse inputs

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.

alt text

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 sphere

using 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)
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

2 Replies

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

Answer by I9ball · Aug 02, 2012 at 11:24 PM

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 ); } } }

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 I9ball · Aug 02, 2012 at 11:26 PM

Can Someone please select my previous post as the answer to this question :) wont lemme do it :/

thanks

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

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Airplane Control, Aim ... Lerp and Vectors 0 Answers

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

Rotating Sphere With Mouse 2 Answers

3D spaceship control using mouse? 0 Answers

Bullet mouse control 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