C
C#2y ago
n305

what is wrong with this code?

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

public class UkkelinLiike : MonoBehaviour
{

public float moveSpeed;

public Rigidbody2D rb;

private Vector2 moveDirection;

// Update is called once per frame
void Update()
{
ProcessInputs();
}
void FixedUpdate()
{
Move();
}

void ProcessInputs()
{
float moveX = Input().GetAxisRaw("Horizontal");
float moveY = Input().GetAxisRaw("Vertical");

moveDirection = new Vector2(moveX, moveY).normalized;
}

void Move()
{
rb.velocity = new Vector2(moveDirection.x * moveSpeed, moveDirection.y * moveSpeed);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UkkelinLiike : MonoBehaviour
{

public float moveSpeed;

public Rigidbody2D rb;

private Vector2 moveDirection;

// Update is called once per frame
void Update()
{
ProcessInputs();
}
void FixedUpdate()
{
Move();
}

void ProcessInputs()
{
float moveX = Input().GetAxisRaw("Horizontal");
float moveY = Input().GetAxisRaw("Vertical");

moveDirection = new Vector2(moveX, moveY).normalized;
}

void Move()
{
rb.velocity = new Vector2(moveDirection.x * moveSpeed, moveDirection.y * moveSpeed);
}
}
4 Replies
n305
n3052y ago
for some reason this doesen't work
n305
n3052y ago
BMo
YouTube
2D Top Down Movement UNITY Tutorial
In this Unity Tutorial we'll cover how to move a 2D character or player around the scene from a top down perspective. This tutorial won't cover animations, but it does cover how to move correctly using Unity's built-in physics system and input system. This tutorial is a great starting point for beginners to get their feet wet with game developm...
khamas
khamas2y ago
$unity