Question by
StarEmpire · May 03, 2016 at 04:35 AM ·
scripting problemvector3space shootermathf.clamp
Vector3 does not contain a constructor that takes 4 arguments
Hi, I have been learning unity for about two days now. I was stuck on the rb = GetComponet< Rigidbody>(); for a little while but now i have a new error with Vector3 and the Mathf.Clamp variables.
I don't know what i am looking for to fix this. it is probably very obvious/simple.
public class Boundary
{
public float xMin, xMax, zMin, zMax;
}
public class PlayerController : MonoBehaviour
{
public float speed;
public Boundary boundary;
public Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.velocity = movement * speed;
rb.position = new Vector3
(
Mathf.Clamp(rb.position.x, boundary.xMin, boundary.xMax),
0,0f,
Mathf.Clamp(rb.position.z, boundary.zMin, boundary.zMax)
);
}
}
Comment
Well, you're passing 4 arguments in vector3 ( at line 25). I guess you need to replace 0,0f with 0.0f. That will resolve this error.
Your answer
Follow this Question
Related Questions
Movement Sticking 0 Answers
How too climb a ladder with the FPS Controller correctly 0 Answers
How to rotate pseudo 'world' around origin? (similar to Kerbal Space Program) 0 Answers
Unity lerp between two textures based on the distance from an object via shaders 0 Answers
Space Shooter tutorial - Mathf.clamping boundaries 0 Answers