I can’t figure out how to add a constant velocity vector, a character should, like, magnetize to a wall or ceiling, add velocity to the ceiling so that if you touch the ceiling, the vector speed up, the character drops down, put more force than gravity does not help
[SerializeField] private float m_MaxSpeed = 10f; //speed x axis [SerializeField] private float m_MaxSpeedup = 6f; [SerializeField] private float m_JumpForce = 400f; [Range(0, 1)] [SerializeField] private float m_PotolokSpeed = .5f; [SerializeField] private bool m_AirControl = false; [SerializeField] private LayerMask m_WhatIsGround; [SerializeField] private LayerMask m_whatiswall; [SerializeField] private LayerMask m_whatispotolok; private Transform m_GroundCheck; const float k_GroundedRadius = .4f; const float k_wallradius = .6f; private bool m_Grounded; private bool m_walled; private bool m_potolok; private Vector2 _speed; //private bool m_potolok; private Transform m_PotolokCheck; private Transform m_wallingcheck; const float k_PotolokRadius = .4f; private Animator m_Anim; private Rigidbody2D m_Rigidbody2D; private bool m_FacingRight = true; void Update() { if (m_Grounded && Input.GetKeyDown(KeyCode.Space)) { m_Rigidbody2D.AddForce(new Vector2(0f, m_JumpForce)); //jump on ground } if (m_walled && !m_Grounded && Input.GetKeyDown(KeyCode.Space)) // jump on wall { m_Rigidbody2D.velocity =new Vector2(6f, 6f); } if (m_potolok && Input.GetKeyDown(KeyCode.Z)) // { m_Rigidbody2D.AddForce(new Vector2(0f,3)); } } private void Awake() { // Setting up references. m_GroundCheck = transform.Find("GroundCheck"); m_PotolokCheck = transform.Find("PotolokCheck"); m_wallingcheck = transform.Find("WallingCheck"); m_Anim = GetComponent<Animator>(); m_Rigidbody2D = GetComponent<Rigidbody2D>(); } private void FixedUpdate() { { m_Grounded = false; Collider2D[] colliders = Physics2D.OverlapCircleAll(m_GroundCheck.position, k_GroundedRadius, m_WhatIsGround); for (int i = 0; i < colliders.Length; i++) { if (colliders[i].gameObject != gameObject) m_Grounded = true; } m_Anim.SetBool("Ground", m_Grounded); //vertical animation m_Anim.SetFloat("vSpeed", m_Rigidbody2D.velocity.y); } { m_walled = false; Collider2D[] colliders = Physics2D.OverlapCircleAll(m_wallingcheck.position, k_wallradius, m_whatiswall); for (int i = 0; i < colliders.Length; i++) { if (colliders[i].gameObject != gameObject) m_walled = true; } m_Anim.SetBool("Wall", m_walled); } { m_potolok = false; Collider2D[] colliders = Physics2D.OverlapCircleAll(m_PotolokCheck.position, k_PotolokRadius, m_whatispotolok); for (int i = 0; i < colliders.Length; i++) { if (colliders[i].gameObject != gameObject) m_potolok = true; } m_Anim.SetBool("Potolok", m_potolok); } } public void Move(float move, bool potolok, bool jump, bool jumpAx)// { // if (!potolok && m_Anim.GetBool("Potolochnik")) { // анимация при остановке на потолке if (Physics2D.OverlapCircle(m_PotolokCheck.position, k_PotolokRadius, m_WhatIsGround)) { potolok = true; } } m_Anim.SetBool("Potolochnik", potolok); if (m_Grounded || m_AirControl) { move = (potolok ? move * m_PotolokSpeed : move); m_Anim.SetFloat("Speed", Mathf.Abs(move)); m_Rigidbody2D.velocity = new Vector2(move * m_MaxSpeed, m_Rigidbody2D.velocity.y); if (move > 0 && !m_FacingRight) { Flip(); } else if (move < 0 && m_FacingRight) { Flip(); } } if (m_Grounded && jump && m_Anim.GetBool("Ground")) { m_Grounded = false; m_Anim.SetBool("Ground", false); m_Rigidbody2D.AddForce(new Vector2(0f, m_JumpForce)); } } private void Flip() { m_FacingRight = !m_FacingRight; Vector3 theScale = transform.localScale; theScale.x *= -1; transform.localScale = theScale; } } }