공격후에 미끄러지는 오류
236
작성한 질문수 1
공격이펙트 마무리 강의를 마쳤는데, 공격시 바라보는 방향으로 힘이 주어져서 더 빨리 이동하는데, 딱 딱 대시하고 멈추지가않고, 스르륵 미끄러집니다. 무엇이 문제일까요?
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);
}
}
답변 1
0
영상을 몇번 돌려보니, Player의 Mass가 2, JumpUp이 10이더군요, 저는 Mass를1, JumpUp을 5로 했었는데, Mass를 2로 바꾸고 나니까 조금 더 자연스러운 것 같습니다.
영상에선 저처럼 마구잡이로 좌우로 안움직이기도하고 확대가 안되서, 미끄러지는지아닌지 모르겠다만, 제건 좌우막 움직이면서 공격하면 아직도 조금 미끄러지긴하는데, 제가 바꾼방식이 문제의 원인해결이 맞을지 잘 모르겠어요
소스를 받을 수 있는 링크가 있을까요?
0
49
2
프로덕션 부분 사용 불가
0
61
2
접근지정자
0
57
2
섹터2 5강 Authconfig 문의
0
41
1
in-app purchasing 버튼의 install 버튼이 비활성화되어있을때 어떻게 해결해야하나요 ?
0
48
2
유니티 제외 설치한 프로그램들 및 파일 삭제 방법
0
47
1
깃허브에서 콤피유아이 매니저 설치하는게 안됩니다.
0
64
2
5강, 오류 수정과 관련해서
0
63
2
컴퓨터를 껐다가 클로드 코드 다시 키는 방법 알려주세요.
0
54
1
MA-POCA 알고리즘 응용 질문
0
41
1
Pivot을 마우스로 클릭하고 드래그해도 움직이 않아서 혹시 아시는 부분이 있나 해서 문의 남깁니다.
0
39
1
클로드에 텍스트 없이 이미지만 보낼경우 에러가 생깁니다
0
67
2
클로드 코드 API 요금관련 질문
0
82
1
자꾸만 번거롭게 해서 죄송합니다.....
0
117
2
이거 후속 강의는 없는 건가요? ㅠㅠ
0
103
2
이거 후속 강의는 없는 건가요? ㅠㅠ
0
67
1
마우스 방향으로 공격을 하고 싶습니다.
0
631
1
스크립트 오류 관련
0
297
2
강좌가 마음에 드는데 심화과정 만드실 계획 있으신가요?
1
268
1
계단에서 착지시 문제점!
0
270
1
4번째 강의 질문
0
246
2
강의 질문드립니다.
0
426
4
엣지콜라이더설치후 폴리싱 관련된 부분 질문드립니다.
0
446
2
강의 순서가 이상해 질문 올립니다~
1
367
2





