using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MakeRun : MonoBehaviour
{
public float v = 5.0f;
public float y_v = 0.0f;
public float jump_power = 5.0f;
private float G = 9.8f;
private bool ground;
private Vector3 charVector;
private CharacterController char_ctrl;
void Start()
{
char_ctrl = GetComponent<CharacterController>();
ground = true;
charVector = Vector3.zero;
}
void Update()
{
charVector.x = -v;
charVector.y = y_v;
charVector.z = Input.GetAxisRaw("Vertical") * v;
char_ctrl.Move(charVector * Time.deltaTime);
if (Input.GetKeyDown("space") && ground)
{
charVector.y = jump_power;
ground = false;
}
if (!ground)
{
}
}
}
์ ํ ์ฝ๋๋ฅผ char_ctrl.Move() ์๋ก ์ฌ๋ ค
y_v ๊ฐ๋ ๋ฐ๊ฟ์ผ์ง
์์ง์๋ ๋ญ๋ก ๋ฐ๊ฟ์ผํจ?
charVector.y๊ฐ ์์์ 0์ผ๋ก ์ด๊ธฐํ๋๊ณ ์์ผ๋ ์คํ์ด์ค๋ฐ๋๋ฌ๋ ๊ณ์ 5์์ 0์ผ๋ก ์ด๊ธฐํ๋๊ณ ์๋์ค์ด์๋
๊ทธ๋ผ ๋งจ์ฒจ์ ๋ฒกํฐ ์ด๊ธฐํํ๋๊ฑฐ ์ง์ฐ๊ณ ์ ํํ ๋ ์ถ๊ฐ๋ก ์๋๊ฐ๋ง ๋ฃ์ด์ฃผ๋ฉด ๋๋๊ฑฐ์?
์ฒจ์ ๋ฒกํฐ.y๋ฅผ 0์ผ๋ก ์ด๊ธฐํํ๋๊ฐ์ ์ง์ฐ๋ฉด ์คํ์ด์ค๋ฐ๋ฅผ๋๋ ์๋ ๋ฒกํฐ.y๊ฐ jump_power๊ฐ์ ๋ฐ์์ฑ๋ก ๊ณ์ ์๋ก ํฅํ๊ฒ๋ ๊ฒ์
๊ทผ๋ฐ ๊ทธ๋ฌ๋ฉด ๋ฌดํ์์น์ ํ๊ฒ๋๋๊น ๋ฒกํฐ.y๊ฐ์ด 0๋ณด๋ค ํด๋ ์ฒ์ฒํ ๋ค์ 0์ด๋๋๋กํ๋ ์ฝ๋๋ฅผ ๋ฃ์ด์ฃผ๋ฉด ๋ง์ฌํด๊ฒฐ