장점
특징
코드
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public float moveSpeed;
public float rotateSpeed;
private Rigidbody playerRigidbody;
void Start()
{
playerRigidbody = GetComponent();
}
void FixedUpdate()
{
Move();
Rotate();
}
void Move()
{
float input = Input.GetAxis("Vertical");
Vector3 moveDistance = input * transform.forward * moveSpeed * Time.deltaTime;
playerRigidbody.MovePosition(playerRigidbody.position + moveDistance);
}
void Rotate()
{
float input = Input.GetAxis("Horizontal");
float turn = input * rotateSpeed * Time.deltaTime;
playerRigidbody.rotation = playerRigidbody.rotation * Quaternion.Euler(0f, turn, 0f);
}
}
'이전 게시물들 > 메모1' 카테고리의 다른 글
Random.Range(int, int) (0) | 2020.01.16 |
---|---|
RigidBody를 이용한 이동, 회전2 (0) | 2019.12.23 |
Player 이동, 애니메이션 (0) | 2019.12.10 |
PlayerInput.cs (0) | 2019.12.10 |
이동 (0) | 2019.12.07 |