Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Andy 1 · Feb 25, 2010 at 04:25 PM · mousepathcircular

Mouse driven circular movement

I want the player to move in a circle. I did the following using cursor keys to move. I simply had the camera looking at 0,0,0 and the player at 0, -5.0, 0. Using left and right had the object moving in a circle with a radius of 5.0

var speed = 100.0;

function Update () {

 var x = Input.GetAxis("Horizontal") * Time.deltaTime * speed;
 transform.RotateAround(Vector3.zero, Vector3.forward, x);

}

The problem is when in the top half of the screen, left moves right, right moves left, which is counter-intuituve for many, plus it is a digital movement.

I was looking for a similar movement, but the player clicks the mouse, the code works out the angle from 0, 0, 0 and moves the player smoothly to that angle (either constant speed or accelerating, but preferably acceleration).

A secondary consideration is how to deal with multiple clicks. I'm currently thinking it moves to click1, then moves to click2, etc. The other possibility is always go towards the latest click.

I'm struggling to understand how to deal with angles, so help on any stage of this problem is most welcome.

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
Best Answer

Answer by andeeee · Feb 25, 2010 at 04:54 PM

You can get the location of a mouse click in world space by calling Camera.ScreenToWorldPoint on the current mouse position. Since the centre of the circle is at <0,0,0> this location can also be used as a direction vector.

If the player needs to stay exactly the same distance from the centre, you could simplify things by putting the player into a parent object at a set distance from the anchor point. Then, instead of using transform.RotateAround, you could just rotate the parent object to move the character around. It is straightforward to make a rotation from the clicked direction vector using Quaternion.LookRotation. You can sweep smoothly between the player's current rotation and the new rotation using Quaternion.Slerp.

Comment
Add comment · Show 1 · 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 Andy 1 · Mar 02, 2010 at 05:27 PM 0
Share

Thank you for the help. I'm still learning. $$anonymous$$ost of Unity has been quite easy to understand, but something just don't click, mouse input and dealing with angles have been my biggest problems. I have re-read the sections you mentioned, but I still don't get it. This is the nearest I have got to anything working, and it is rubbish.

var speed = 100.0;

function Update () {

var relativePos = Vector3.zero - Input.mousePosition; var rotation = Quaternion.LookRotation(relativePos); transform.rotation = Quaternion.Slerp(transform.rotation, rotation, speed * Time.deltaTime);

}

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

Move object towards mouse but if mouse moves object fallows it's original path 0 Answers

Checking if mouse dragged from one point to another 2 Answers

progressive circular player movement 1 Answer

Having trouble with implementing circular player movement 1 Answer

Need Help: Unity draw-to-follow? 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