38b0ca3ce4de76a167b9f68b12d21a1d767c376ca017ef




이거 왜 이럼


아랜 코드임


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
 
public class PlayerController : MonoBehaviour
{
    public float speed = 5;
    public float jumpSpeed = 10;
 
    int jumpCount = 0;
    public Transform currentFloor = null;
 
    Rigidbody2D rigid;
    Collider2D col;
 
    private void Awake()
    {
        rigid = GetComponent<Rigidbody2D>();
        col = GetComponent<Collider2D>();
    }
 
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (Input.GetKey(KeyCode.DownArrow))
            {
                List<ContactPoint2D> contacts = new List<ContactPoint2D>();
 
                rigid.GetContacts(contacts);
 
                foreach (var obj in contacts)
                {
                    if (obj.collider.CompareTag("Platform"))
                    {
                        obj.collider.GetComponent<Platform>().ExcludeLayerForFrames(gameObject, 25);
                    }
                }
            }
            else
            {
                if (jumpCount > 0)
                {
                    jumpCount--;
                    rigid.velocity = new Vector2(rigid.velocity.x, jumpSpeed);
                }
            }
        }
    }
 
    private void FixedUpdate()
    {
        float x = Input.GetAxisRaw("Horizontal");
 
        transform.position += Vector3.right * (x * Time.fixedDeltaTime * speed);
 
        currentFloor = null;
 
        if (rigid.velocity.y == 0)
        {
            List<ContactPoint2D> contacts = new List<ContactPoint2D>();
 
            rigid.GetContacts(contacts);
 
            foreach (var obj in contacts)
            {
                if (obj.collider.CompareTag("Platform"|| obj.collider.CompareTag("Floor"))
                {
                    jumpCount = 2;
                    currentFloor = obj.collider.transform;
                }
            }
        }
    }
}
 
cs




이동은 transform으로 하고 점프는 velocity로 하고 있음


왜이러는지 감도 안오네 velocity 내부 연산 이슈인가

흔한 문제일거 같아서 검색해봤는데 모르겠네