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 /
avatar image
0
Question by thegoatman989 · May 16, 2021 at 10:29 PM · stickstickingsticky

How do I make soft body stick to ground?

Hello everyone, I am making a game and I need help. I want to make my soft body stick to the ground like in the game stick with it but there are no videos on how to do that. I am using a trajectory line to move my player so I want to make it so when some one lets go of the mouse, then the character unsticks and moves. Thanks!

Comment
Add comment · Show 4
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
avatar image Llama_w_2Ls · May 17, 2021 at 10:39 AM 0
Share

If the object is grounded or stuck to a wall, you could freeze its position, until the player adds a force to it.

avatar image thegoatman989 · May 17, 2021 at 10:37 PM 0
Share

Would I attach the script to the player or the ground though?

avatar image Llama_w_2Ls thegoatman989 · May 18, 2021 at 11:02 AM 0
Share

The player. Freezing the position needs access to the rigidbody component (which the player has), or the transform component (depending on which way you want to freeze the player).

avatar image thegoatman989 · May 19, 2021 at 06:00 PM 0
Share

Ok so I got it working kind of, but if I try to move, it won't unstick. do you think I should use a bool variable instead?

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by thegoatman989 · Jun 01, 2021 at 08:44 PM

FIXED: I finally got it working! Here's the script!

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Stick : MonoBehaviour
 {
     bool canMove = false;
     Rigidbody2D rb;
 
     void Start()
     {
         rb = GetComponent<Rigidbody2D>();
     }
 
     void OnCollisionEnter2D(Collision2D collison)
     {
         if (collison.transform.tag != "Player")
         {
             if (!Input.GetMouseButtonDown(0))
             {
                 rb.constraints = RigidbodyConstraints2D.FreezePositionY | RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezeRotation;
                 canMove = true;
                 //print ("Col");
                 //print ("Enter");
             }
         }
     }
 
     void OnCollisionExit2D(Collision2D collision)
     {
         if (collision.transform.tag != "Player")
         {
             rb.constraints = RigidbodyConstraints2D.None;
             canMove = false;
             //print ("Exit");
         }
     }
 
     void OnCollisionStay2D(Collision2D collision)
     {
         if (collision.transform.tag != "Player")
         {
             //body.constraints = RigidbodyConstraints2D.FreezePositionY | RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezeRotation;
             canMove = true;
             //rigidbody2D.v = new Vector2 (0, 0);
             //print ("Stay");
         }
     }
 
     void Update()
     {
         if (Input.GetMouseButtonUp(0))
         {
             rb.constraints = RigidbodyConstraints2D.None;
 
         }
     }
 }

Original credit goes to this person! I just modified it UWU link text

Comment
Add comment · Share
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

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

117 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

Related Questions

Question about configuration of physics 3D materials 0 Answers

[Closed]Player Sticking to Floor in Zero Grav 1 Answer

How to perfecly snap two objects (control key is not working) 1 Answer

How to stick 2D textures? 0 Answers

Using Right Analog stick to fire weapon. 1 Answer


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