• 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
Question by Bottle_And_A_Gun · May 06, 2018 at 05:33 PM · movement2d-platformermovement scripticeslip

2D Platformer, Icy material?

Hi,

Bare with me, I am still completely new to Unity. I have a simple 2D platformer that is coming along decently and I want the final level to be set in a Ice World. The premise would be that the player would find it quite difficult to control the player because after they stop moving, the character would still move because of the slipperiness of the ice.

My issue is that I do not know how to implement this. After doing a bit of research, I couldn't find anything that I could personally comprehend since it's all to do with physics. I know it isn't as simple as making a 2D physics material. Here is my player movement script which is a mash up of my own code and other code across the web, apologies if it's a mess :)

 public class PlayerMovement : MonoBehaviour {
 
     public int speed = 2;
     [Range(1, 10)]
     public float jumpVelocity = 5f;
     public float fallMultiplier = 2.5f;
     public float lowJumpMultiplier = 2f;
 
     public float groundedSkin = 0.5f;
     public LayerMask mask;
 
     public AudioClip jump;
 
     private AudioSource audioSource;
 
     private SpriteRenderer mySpriteRenderer;
     Animator anim;
 
     bool jumpRequest;
     bool grounded;
 
     Vector2 playerSize;
     Vector2 boxSize;
 
     Rigidbody2D rb;
 
     private void Awake()
     {
         rb = GetComponent<Rigidbody2D>();
 
         playerSize = GetComponent<BoxCollider2D>().bounds.size;
         boxSize = new Vector2(playerSize.x, groundedSkin);
 
         mySpriteRenderer = GetComponent<SpriteRenderer>();
         anim = GetComponent<Animator>();
     }
 
     // Update is called once per frame
     void Update()
     {
         anim.SetFloat("Speed", Mathf.Abs(Input.GetAxis ("Horizontal")));
 
         if (Input.GetAxisRaw("Horizontal") > 0)
         {
             transform.Translate(speed * Time.deltaTime, 0f, 0f);
             //rb.velocity = new Vector2(speed * Time.deltaTime, 0f);
             mySpriteRenderer.flipX = false;
         }
 
         if (mySpriteRenderer != null)
         {
             if (Input.GetAxisRaw("Horizontal") < 0)
             {
                 transform.Translate(-speed * Time.deltaTime, 0f, 0f);
                 //rb.velocity = new Vector2(speed * Time.deltaTime, 0f);
                 mySpriteRenderer.flipX = true;
             }
         }
 
         if (rb.velocity.y < 0)
         {
             rb.velocity += Vector2.up * Physics2D.gravity.y * (fallMultiplier - 1) * Time.deltaTime;
         }
         else if ((rb.velocity.y > 0 && !Input.GetKey(KeyCode.UpArrow)))
         {
             rb.velocity += Vector2.up * Physics2D.gravity.y * (lowJumpMultiplier - 1) * Time.deltaTime;
         }
 
         if ((Input.GetKeyDown(KeyCode.UpArrow) && grounded))
         {
             jumpRequest = true;
             AudioSource.PlayClipAtPoint(jump, this.transform.position);
         }
 
         if (jumpRequest)
         {
             rb.AddForce(Vector2.up * jumpVelocity, ForceMode2D.Impulse);
 
             jumpRequest = false;
             grounded = false;
         }
         else
         {
             Vector2 boxCenter = (Vector2)transform.position + Vector2.down * (playerSize.y + boxSize.y) * 0.5f;
             grounded = (Physics2D.OverlapBox (boxCenter, boxSize, 0f, mask) != null);
         }
     }
 }

To round it up, if anyone could help me understand where to implement the icy movement code and specifically how to do so, would be greatly appreciated. If you need any other resources from the game, feel free to ask.

Thanks!

Comment

People who like this

0 Show 0
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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

189 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

Related Questions

character falls through floor help me (box collider for floor, and person rigidbody, circle character&controller) 1 Answer

How to make a 2d platformer with a rolling ball as a player? 1 Answer

2D Movement System (Stop Movement on Collision) 1 Answer

SteamVR Movement based on controller direction 0 Answers

pc movement to android,help with a pc movment to work on android 0 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