Day 1 Solutions






Player Character Motion


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

//rigidbody2D
public Rigidbody2D rbody;

//speed
public float speed = 4f;

//vector2 input direction
public Vector2 inputDirection;

// Update is called once per frame
void Update()
{
//use input.getaxis to get input from keyboard or joysticks
float horizontal = Input.GetAxis("Horizontal");
float vertical = Input.GetAxis("Vertical");


//and assign that to this vector2 i made...
inputDirection.x = horizontal;
inputDirection.y = vertical;

}

private void FixedUpdate()
{
Vector2 position;
position = transform.position;
position += inputDirection * Time.deltaTime * speed;

//move that rigidbody around speed input direction
rbody.MovePosition(position);
}