- Home /
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);
}
}
at line 94 I changed Vector2 to Vector3 but didnt solve
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);
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.
Your answer
Follow this Question
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