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 Myrmidou · Jun 07, 2014 at 09:18 PM · joystickclamp

How to clamp ovally?

Hi. First of all, forgive me if my english isn't the best you've ever seen, I'll try to do my best. I started unity a few weeks ago and I'm currently working on a kind of 2d catapult. I was wondering how to clamp the position of an object (here the paddle) ovally.

This is my scene

alt text

and I've already done this but I think that it's much more complexe considering that what I want do looks like a 2d oval joystick

alt text

I hope I've been clear enough.

capture1.png (13.4 kB)
capture2.png (4.8 kB)
Comment
Add comment · Show 2
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 NoseKills · Jun 08, 2014 at 06:59 AM 0
Share

I don't quite understand what is wrong with your current solution. Is it that the current system works by limiting point3 in relation to points 1 and 2, and you'd want a paddle that's tied from both ends?

avatar image Myrmidou · Jun 09, 2014 at 08:44 AM 0
Share

I'd want the paddle to stay close from each point, drawing an ovally shape. For me, the most difficult part is to clamp the whole thing and to make the paddle follow the pointer/finger even if it's outside of the limit, like with a 2d joystick.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by fafase · Jun 08, 2014 at 08:42 AM

I understand you want to clamp the position of the pad around the two points and since you have two points, it creates some kind of oval shape (it is actually more of a 8 shape, if I get it right).

You need to first check which of the two objects you are closer to, and then clamp the distance within a radius:

 Transform closest;
 
 Vector2 dist1 = Vector2.Distance(p1.position, transform. position);
 Vector2 dist2 = Vector2.Distance(p2.position, transform. position);
 
 if (dist1 < dist2)closest = dist1;
 else closest = dist2;
 
 // Clamp your value using closest.
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 Myrmidou · Jun 08, 2014 at 04:59 PM 0
Share

I tried to clamp with Clamp$$anonymous$$agnitude but I think that there is a problem somewhere. Also, if what I want te do is a kind of slingshot, I think that it's better to use farthest.

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

22 People are following this question.

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

Related Questions

C# Clamp joystick rotation 0 Answers

Joystick Controller Problem 0 Answers

Show Joystick on the left part of the screen only 1 Answer

How to get RenderTexture non-square? 2 Answers

door script problems 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