Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more..
    Dismiss Notice
  3. Dismiss Notice

Question 3D Spiderman Swiniging System using only Character Controller without Rigidbody

Discussion in 'Scripting' started by ydanboos, May 12, 2021.

  1. ydanboos

    ydanboos

    Joined:
    Aug 20, 2016
    Posts:
    5
    Hey there,

    I've been trying to get a swinging system to work for the past 3 weeks.
    I've seen several tutorials that use Spring Joints, but that doesn't work well with Character Controller and my player always ends up falling through collision when the spring joint is activated.
    So I'm trying to use the pendulum equation to achieve the swing movement but it totally not working.
    I don't know if this is the right way to make a swing system so I'm hoping someone can help me with how to fix this or what other technique I should use.

    Code (CSharp):
    1. // Update is called once per frame
    2.     void Update()
    3.     {
    4.         Vector3 velocity = (transform.position - previousPosition) / Time.deltaTime;
    5.         previousPosition = transform.position;
    6.  
    7.         float dot = Vector3.Dot(velocity, transform.position - anchorPoint.transform.position);
    8.         Vector3 normalize = Vector3.Normalize(transform.position - anchorPoint.transform.position);
    9.         swingMovement = ((normalize * dot) * -2f);
    10.  
    11.         Vector3 gravity = Vector3.down * 9.81f * Time.deltaTime;
    12.  
    13.         character.Move((gravity + swingMovement) * Time.deltaTime);
    14.     }
     

    Attached Files:

  2. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,917
  3. ydanboos

    ydanboos

    Joined:
    Aug 20, 2016
    Posts:
    5
    I'm not sure if I'm doing something wrong or his explanation doesn't apply so much to the way Unity works.
    But there must be a way to do this with Character Controller instead of Rigidbody.
     
  4. ydanboos

    ydanboos

    Joined:
    Aug 20, 2016
    Posts:
    5
    bump, still can't figure this out :(