Skip to content

Instantly share code, notes, and snippets.

@onlyoneaman
Created November 8, 2021 11:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onlyoneaman/ac26fe1f059986976d4cb94219e312bb to your computer and use it in GitHub Desktop.
Save onlyoneaman/ac26fe1f059986976d4cb94219e312bb to your computer and use it in GitHub Desktop.
Roll Ball Player Extension Script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerController : MonoBehaviour
{
public float speed = 0;
private Rigidbody rb;
private float movementX;
private float movementY;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void OnMove(InputValue movementValue)
{
Vector2 movementVector = movementValue.Get<Vector2>();
movementX = movementVector.x;
movementY = movementVector.y;
}
void FixedUpdate()
{
Vector3 movement = new Vector3(movementX, 0.0f, movementY);
rb.AddForce(movement * speed);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment