Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class BallMovement : MonoBehaviour
- {
- [SerializeField]
- private float _speed = 3f;
- [SerializeField]
- private float _ballRadius = 1f;
- private float _ballPerimeter;
- void Start()
- {
- _ballPerimeter = 2f * Mathf.PI * _ballRadius;
- }
- void OnDrawGizmos()
- {
- Gizmos.color = Color.yellow;
- Gizmos.DrawWireSphere(transform.position, _ballRadius);
- }
- void Update()
- {
- var input = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
- var acceleration = input * _speed;
- var toAdd = acceleration * Time.deltaTime;
- transform.position += toAdd;
- var horizontalDistTraveled = toAdd.x;
- var angle = horizontalDistTraveled / _ballPerimeter * 360f;
- transform.Rotate(Vector3.back, angle);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment