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

public class CharacterMove : MonoBehaviour
{
public Transform cameraTransform;
// ์นด๋ฉ”๋ผ ์›€์ง์ž„ ๋ฐ›์•„์˜ค๋Š” cameraTransform ๋ณ€์ˆ˜ ์„ ์–ธ

public CharacterController characterController;
// CharacterController ์— 3D ์˜ค๋ธŒ์ ํŠธ ์ ์šฉ ์œ„ํ•œ characterController ๋ณ€์ˆ˜ ์„ ์–ธ

public float movespeed = 10f;
public float jumppower = 10f;
public float gravity = -20f;
public float yVelocity = 0;

// Start is called before the first frame update
void Start()
{
}

// Update is called once per frame
void Update()
{
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");

Vector3 moveDirection = new Vector3(h, 0, v);
moveDirection = cameraTransform.TransformDirection(moveDirection);
moveDirection *= movespeed;

if(characterController.isGrounded)
{
yVelocity = 0;
if(Input.GetKeyDown(KeyCode.Space))
{
yVelocity = jumppower;
}
}


if(Input.GetKeyDown(KeyCode.F))
{
Debug.Log("GOTO first location");
transform.position = new Vector3(-9, 6, -10);
}

if(transform.position.y < -30f)
{
Debug.Log("Character fell below -30.");
transform.position = new Vector3(-9, 6, -10);
}

yVelocity += (gravity * Time.deltaTime);
moveDirection.y = yVelocity;
characterController.Move(moveDirection * Time.deltaTime);
}
}


ํ•ด๋‹น ์ฝ”๋“œ์—์„œ

if(Input.GetKeyDown(KeyCode.F))
{
Debug.Log("GOTO first location");
transform.position = new Vector3(-9, 6, -10);
}


if(transform.position.y < -30f)
{
Debug.Log("Character fell below -30.");
transform.position = new Vector3(-9, 6, -10);
}

์ผ๋‹จ ์ด๋ถ€๋ถ„์—์„œ transform.position = new ์–ด์ฉŒ๊ณ  ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ์ดˆ๊ธฐ์œ„์น˜๋กœ ํ…”๋ ˆํฌํŠธ๊ฐ€ ์•ˆ๋ฉ๋‹ˆ๋‹ค.....


๊ทธ๋ฆฌ๊ณ  ์ฝ”๋“œ ์ „์ฒด์ ์ธ ๋ถ€๋ถ„์—์„œ ์™œ๊ทธ๋Ÿฌ๋Š”์ง€๋Š” ๋ชจ๋ฅด๊ฒ ๋Š”๋ฐ


if(characterController.isGrounded)
{
yVelocity = 0;
if(Input.GetKeyDown(KeyCode.Space))
{
yVelocity = jumppower;
}
}


์—ฌ๊ธฐ์„œ yVelocity = 0; ๋ถ€๋ถ„ ์—†์• ๋ฉด ์ œ์ž๋ฆฌ์—์„œ ์•„๋ฌด๋Ÿฐ ์›€์ง์ž„ ์—†์ด ์ ํ”„๊ฐ€ ๋˜์ง€๋งŒ ๊ณ„์† ๊ฐ์†Œํ•˜๋Š” yVelocity ๋•Œ๋ฌธ์— ๋‚™ํ•˜์‹œ ๊ฐœ๋น ๋ฅด๊ฒŒ ๋˜๋Š” ๋ฌธ์ œ์ ์ด ์žˆ๊ณ ,

๊ทธ๋ž˜์„œ ์—ญ์‹œ yVelocity = 0 ์œผ๋กœ ์ดˆ๊ธฐํ™” ์‹œํ‚ค๋Š”๊ฑด ๋งž๋Š”๊ฑฐ๊ฐ™์€๋ฐ ์ด๋ ‡๊ฒŒ๋˜๋ฉด ์ œ์ž๋ฆฌ์—์„œ ์ ํ”„๊ฐ€ ์•ˆ๋ฉ๋‹ˆ๋‹ค...


๊ณ ์ˆ˜๋‹˜๋“ค ๋„์™€์ฃผ์„ธ์—ฌ,,,