- Home /
Smooth Player Movement
Hey there. I'm trying to set up movement for the player that somewhat resembles an air hockey puck on a table. The script I currently have looks like this:
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour
{
public GameObject player;
public float speed = 10f;
void Update()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0, moveVertical);
player.transform.Translate(movement * speed * Time.deltaTime);
}
}
The problem I'm having is that when I go into play mode, the player will register the movement and try to move, but will be locked in its starting position. It will pull the object in the direction, but it won't go anywhere and just glitches in place. How can I remedy this?
Answer by 767_2 · Sep 22, 2014 at 09:24 AM
i think your Y is misplaced
Vector3 movement = new Vector3(moveHorizontal, moveVertical, 0 );
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Should character direction come from key press, or third person controller vector3? 0 Answers
How do I set up my players controller script (How do I change the controls used to move and look) 2 Answers
Problem with player movements 1 Answer