Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Movement : MonoBehaviour
- {
- public float speed = 1f;
- public Vector2 boundary;
- private void FixedUpdate()
- {
- Vector2 inputs = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")).normalized * speed;
- Vector3 newpos = transform.position;
- newpos += new Vector3(inputs.x, 0, inputs.y);
- newpos = new Vector3(
- Mathf.Clamp(newpos.x, -boundary.x, boundary.x),
- 3f,
- Mathf.Clamp(newpos.z, -boundary.y, boundary.y)
- );
- transform.position = newpos;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement