Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by TkTintenauge · Aug 16, 2020 at 02:22 AM · position2d-platformersnappingobject referenceedge detection

snapping the Players psosition to another GameObject for a "Ledge grab"

Hi! Another day another coding problem. I use this PlayerMovement script from a tutorial and try to mod it to my liking. I added a WallJump now I tried to implement a LedgeGrab but everything I saw online with this tag didn't help me. I have ledge recognition up and running. Now I want the player to snap to a certain position of the lede when the recognition triggers. There are several GameObjects with the Layer: "Ledge" and I want it to snap to the one that triggered the recognition (m_Ledged). Somehow everything I tried failed.

This is the most part of the script. The ledge recognition ist more at the top of it while the snapping will be near the End.

public class CharacterController2D : MonoBehaviour {
[SerializeField] private LayerMask m_WhatIsLedge; [SerializeField] private Transform m_LedgeGrabCheck; [SerializeField] private Transform Player;

 const float k_LedgeGrabRadius = .2f;
 private bool m_Ledged;
 private Rigidbody2D m_Rigidbody2D;
 private bool m_FacingRight = true;  // For determining which way the player is currently facing.
 private Vector3 m_Velocity = Vector3.zero;


 public UnityEvent OnLandEvent;

 [System.Serializable]
 public class BoolEvent : UnityEvent<bool> { }

 public BoolEvent OnCrouchEvent;
 private bool m_wasCrouching = false;

 private void Awake()
 {
     m_Rigidbody2D = GetComponent<Rigidbody2D>();

     if (OnLandEvent == null)
         OnLandEvent = new UnityEvent();

     if (OnCrouchEvent == null)
         OnCrouchEvent = new BoolEvent();
 }

 private void FixedUpdate()
 {
     bool wasLedged = m_Ledged;
     m_Ledged = false;

     Collider2D[] collidersLedge = Physics2D.OverlapCircleAll(m_LedgeGrabCheck.position, k_LedgeGrabRadius, m_WhatIsLedge);
     for (int i = 0; i < collidersLedge.Length; i++)
     {
         if (collidersLedge[i].gameObject != gameObject && !m_Grounded)
         {
             m_Ledged = true;
             Debug.Log("Ledged");
         }
     }
 }


 public void Move(float move, bool crouch, bool jump)
 {
 
     if (m_Ledged)
     {

    //--------- snap to the  position of the triggering ledge + offset until m_Ledged = false---------

     }
 }

I tried to throw out anything of the script that isn't realted to the problem

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

244 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Problem with a rendering of a 2D sprite 1 Answer

Why does my object move to 0 when I play an animation? 0 Answers

NullReferenceException: Object reference not set to an instance of an object 2 Answers

[SOLVED] Ghost enemy AI that follows the player by copying the players position 0 Answers

2D Unity Instantiate Ragdoll, same Transform as Sprites ( Head, Torso, LArm,RArm,LLeg,RLeg) 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges