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 sreevathsa7 · Jun 02, 2014 at 12:14 PM · errorclampargumentsoverload

No overload for method 'ClampMagnitude' takes '3' arguments

This is the code and it says "Assets/JoyStick.cs(94,57): error CS1501: No overload for method 'ClampMagnitude' takes '3' arguments". --Thank you in advance--

 using UnityEngine;
 using System.Collections;
 
 public class Joystick : TouchLogic 
 {
     public enum JoystickType {Movement, LookRotation, SkyColor};
     public JoystickType joystickType;
     public Transform player = null;
     public float playerSpeed = 2f, maxJoyDelta = 0.05f, rotateSpeed = 100.0f;
     private Vector3 oJoyPos, joyDelta;
     private Transform joyTrans = null;
     public CharacterController troller;
     private float pitch = 0.0f,
     yaw = 0.0f;
     //[NEW]//cache initial rotation of player so pitch and yaw don't reset to 0 before rotating
     private Vector3 oRotation;
     void Start () 
     {
         joyTrans = this.transform;
         oJoyPos = joyTrans.position;
         //NEW//cache original rotation of player so pitch and yaw don't reset to 0 before rotating
         oRotation = player.eulerAngles;
         pitch = oRotation.x;
         yaw = oRotation.y;
     }
     
     void OnTouchBegan()
     {
         //Used so the joystick only pays attention to the touch that began on the joystick
         touch2Watch = TouchLogic.currTouch;
     }
     
     void OnTouchMovedAnywhere()
     {
         if(TouchLogic.currTouch == touch2Watch)
         {
             //move the joystick
             joyTrans.position = MoveJoyStick();
             ApplyDeltaJoy();
         }
     }
     
     void OnTouchStayedAnywhere()
     {
         if(TouchLogic.currTouch == touch2Watch)
         {
             ApplyDeltaJoy();
         }
     }
     
     void OnTouchEndedAnywhere()
     {
         //the || condition is a failsafe so joystick never gets stuck with no fingers on screen
         if(TouchLogic.currTouch == touch2Watch || Input.touches.Length <= 0)
         {
             //move the joystick back to its orig position
             joyTrans.position = oJoyPos;
             touch2Watch = 64;
         }
     }
     
     void ApplyDeltaJoy()
     {
         switch(joystickType)
         {
         case JoystickType.Movement:
             troller.Move ((player.forward * joyDelta.z + player.right * joyDelta.x) * playerSpeed * Time.deltaTime);
             break;
         case JoystickType.LookRotation:
             pitch -= Input.GetTouch(touch2Watch).deltaPosition.y * rotateSpeed * Time.deltaTime;
             yaw += Input.GetTouch(touch2Watch).deltaPosition.x * rotateSpeed * Time.deltaTime;
             
             //limit so we dont do backflips
             pitch = Mathf.Clamp(pitch, -80, 80);
             
             //do the rotations of our camera 
             player.eulerAngles += new Vector3 ( pitch, yaw, 0.0f);
             break;
         case JoystickType.SkyColor:
             Camera.mainCamera.backgroundColor = new Color(joyDelta.x, joyDelta.z, joyDelta.x*joyDelta.z);
             break;
             
         }
     }
     
     Vector3 MoveJoyStick()
     {
         //convert the touch position to a % of the screen to move our joystick
         float x = Input.GetTouch (touch2Watch).position.x / Screen.width,
         y = Input.GetTouch (touch2Watch).position.y / Screen.height;
         //combine the floats into a single Vector3 and limit the delta distance
         
         //If you want a rectangularly limited joystick (used in video), use this
         Vector3 position = new Vector3 (Vector2.ClampMagnitude(x, oJoyPos.x - maxJoyDelta, oJoyPos.x + maxJoyDelta),Vector2.ClampMagnitude(y, oJoyPos.y - maxJoyDelta, oJoyPos.y + maxJoyDelta), 0);//use Vector3.ClampMagnitude instead if you want a circular clamp instead of a square
         
         //If you want a circularly limited joystick, use this (uncomment it)
         //Vector3 position = Vector3.ClampMagnitude(new Vector3 (x-oJoyPos.x, y-oJoyPos.y, 0), maxJoyDelta) + oJoyPos;
         
         
         //joyDelta used for moving the player
         joyDelta = new Vector3(position.x - oJoyPos.x, 0, position.y - oJoyPos.y).normalized;
         //position used for moving the joystick
         return position;
     }
     
     void LateUpdate()
     {
         if(!troller.isGrounded)
             troller.Move(Vector3.down * 2);
     }
 }
Comment
Add comment · Show 1
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 sreevathsa7 · Jun 02, 2014 at 11:36 AM 0
Share

at line 94 I changed Vector2 to Vector3 but didnt solve

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by fafase · Jun 02, 2014 at 12:20 PM

The compiler is dumb and just reports what it sees wrong.

 Vector3 position = new Vector3 (
      Vector2.ClampMagnitude(
          x,                         // one param
          oJoyPos.x - maxJoyDelta,   // two param
          oJoyPos.x + maxJoyDelta)   // three param, mmmm...

      ,Vector2.ClampMagnitude(
           y,                        // one param
           oJoyPos.y - maxJoyDelta,  // two param
           oJoyPos.y + maxJoyDelta)  // oh!! three param again
      , 0);
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 HarshadK · Jun 02, 2014 at 12:23 PM

Check the argument types and format for Vector2.ClampMagnitude which is:

 static Vector2 ClampMagnitude(Vector2 vector, float maxLength);

where the arguments should be of type Vector2 and a float.

You are providing three values to it instead of two. Convert your first two values into a Vector2.

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

21 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

Related Questions

C# No overload for method 'BeOlvasBabok' takes 1 arguments 1 Answer

Csharp error - PLS help :( | error CS1501 1 Answer

[Solved]List.FindIndex error C# 1 Answer

overloaded Raycast 0 Answers

(SOLVED) "No appropriate version of 'UnityEngine.GUI.Toolbar' for the argument list '(UnityEngine.Rect, int, UnityEngine.GUIContent, UnityEngine.GUIStyle)' was found." Help? 1 Answer


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