inflearn logo
강의

講義

知識共有

UnityとC#で学ぶ カタナゼロスタイルゲームの作り方 (基本編)

攻撃エフェクト仕上げ

공격후에 미끄러지는 오류

223

Hants

投稿した質問数 1

0

공격이펙트 마무리 강의를 마쳤는데, 공격시 바라보는 방향으로 힘이 주어져서 더 빨리 이동하는데, 딱 딱 대시하고 멈추지가않고, 스르륵 미끄러집니다. 무엇이 문제일까요?


using System.Collections;

using System.Collections.Generic;

using System.IO;

using UnityEditor;

using UnityEngine;

using UnityEngine.UIElements;

public class Player : MonoBehaviour

{

public float speed = 5;

public float jumpUp = 1;

public float power = 5;

public Vector3 direction; //방향을 위한 Vector3형 변수

public GameObject slash;

Animator pAnimator; //애니메이션 관리를 위함

Rigidbody2D pRig2D; //물리효과처리 +

SpriteRenderer sp;

void Start()

{

pAnimator = GetComponent<Animator>();

pRig2D = GetComponent<Rigidbody2D>();

direction = Vector2.zero;

sp = GetComponent<SpriteRenderer>();

}

void KeyInput()

{

direction.x = Input.GetAxisRaw("Horizontal");

if (direction.x < 0)

{

//left

sp.flipX = true;

pAnimator.SetBool("Run", true);

}

else if (direction.x > 0)

{

//right

sp.flipX = false;

pAnimator.SetBool("Run", true);

}

else if (direction.x == 0)

{

pAnimator.SetBool("Run", false);

}

if (Input.GetMouseButtonDown(0))

{

pAnimator.SetTrigger("Attack");

}

}

void Update()

{

//클래스 사용

KeyInput();

Move();

if (Input.GetKeyDown(KeyCode.W))//W키 눌렀을때

{

if (pAnimator.GetBool("Jump") == false)

{

Jump();

pAnimator.SetBool("Jump", true);

}

}

}

private void FixedUpdate()

{

Debug.DrawRay(pRig2D.position, Vector3.down, new Color(0, 1, 0));

RaycastHit2D rayHit = Physics2D.Raycast(pRig2D.position, Vector3.down, 1, LayerMask.GetMask("Ground"));

if (pRig2D.velocity.y < 0)

{

if (rayHit.collider != null)

{

if (rayHit.distance < 0.7f)

{

pAnimator.SetBool("Jump", false);

}

}

}

}

//움직임 함수

public void Move()

{

transform.position += direction speed Time.deltaTime;

}

public void AttSlash()

{

//플레이어 오른쪽

if (sp.flipX == false)

{

pRig2D.AddForce(Vector2.right * power, ForceMode2D.Impulse);

GameObject go = Instantiate(slash, transform.position, Quaternion.identity);

go.GetComponent<SpriteRenderer>().flipX = sp.flipX;

}

else //왼쪽

{

pRig2D.AddForce(Vector2.left * power, ForceMode2D.Impulse);

GameObject go = Instantiate(slash, transform.position, Quaternion.identity);

go.GetComponent<SpriteRenderer>().flipX = sp.flipX;

}

}

//점프 함수

public void Jump()

{

//벡터값 제로

pRig2D.velocity = Vector2.zero; //제로로 해줘야 이전에 있던 값(힘)이 사라진다?

//위로 힘 가해주기

pRig2D.AddForce(new Vector2(0, jumpUp), ForceMode2D.Impulse);

}

}

 

C# unity

回答 1

0

Hants

영상을 몇번 돌려보니, Player의 Mass가 2, JumpUp이 10이더군요, 저는 Mass를1, JumpUp을 5로 했었는데, Mass를 2로 바꾸고 나니까 조금 더 자연스러운 것 같습니다.
영상에선 저처럼 마구잡이로 좌우로 안움직이기도하고 확대가 안되서, 미끄러지는지아닌지 모르겠다만, 제건 좌우막 움직이면서 공격하면 아직도 조금 미끄러지긴하는데, 제가 바꾼방식이 문제의 원인해결이 맞을지 잘 모르겠어요

OAuth방식 강의 문의

0

11

0

싱글턴패턴

0

6

1

코드 관련 질문

0

21

2

섹션7 수업자료 업로드 부탁드립니다.

0

22

2

Dictionary Key를 int에서 string으로 변경한 이유에 대한 문의

0

19

1

프로젝트 질문 문의

0

46

1

UI 기능 관련 질문이 있습니다!

0

37

2

03-01 (16. CharacterController)

0

31

2

TLS 질문드립니다.

0

43

2

Task 구현 28:36 Equals 에서 잘 모르는 부분이 있습니다.

0

27

2

SpinLock과 컨텍스트스위칭에 대해 질문 남겨요.

0

46

2

픽셀 좌표 스크린 좌표

0

33

0

Locomotion랑 Turn 이 꼭 부모 자식 관계일 필요가 있나요?

0

25

1

자꾸만 번거롭게 해서 죄송합니다.....

0

69

2

이거 후속 강의는 없는 건가요? ㅠㅠ

0

76

2

이거 후속 강의는 없는 건가요? ㅠㅠ

0

52

1

마우스 방향으로 공격을 하고 싶습니다.

0

609

1

스크립트 오류 관련

0

287

2

강좌가 마음에 드는데 심화과정 만드실 계획 있으신가요?

1

255

1

계단에서 착지시 문제점!

0

263

1

4번째 강의 질문

0

232

2

강의 질문드립니다.

0

395

4

엣지콜라이더설치후 폴리싱 관련된 부분 질문드립니다.

0

427

2

강의 순서가 이상해 질문 올립니다~

1

353

2