Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 tieTYT1 · Apr 18, 2016 at 01:27 PM · 2d-platformer2d-physicsice

Pushing a sliding block that falls straight down

I'm trying to copy the game mechanics of Fire n' Ice. It's a side scrolling, 2D puzzle game. I want to be able to push an ice block and have it slide across the floor until it hits an obstacle or falls off a ledge. If it falls of a ledge, I want it to fall straight down. I'm very new to Unity and I'm not sure how to do this.

If I give the block a RigidBody2D and a BoxCollider2D, my player can push against it. But:

  1. It slows down to a stop on the platform. I'm confused why it does this because I set the ice cube's drag to be 0.

  2. If it falls off a ledge, it continues moving on the X axis while it's falling. Instead, I'd like it to fall straight down.

How can I achieve physics like this?

Comment
Add comment · Show 1
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 Cherno · Apr 18, 2016 at 03:34 PM 0
Share

First, you should ask your self if using Unity's Physics system is the way to go here, as it is hard to get complete control over how things interact witch each other. You could try using physics materials that simulate a frictionless surface for the block and/or icy ground. Combine this with (or only use) one or more raycasts (more for better simulation) towards the sides of the block and downward to check if it hits a wall (set velocity to zero/stop movement) and to check if it's grounded or not. If you are using pure tile-based approach, you could even control the movement purely by script by having a way to check the terrain (or lack thereof) of each tile and use that in relation to the block's current position to make it move or not move.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by DivinityStripes · Apr 19, 2016 at 05:02 AM

Problem 1: "Icy Physics":

You can apply a physics material 2D simulating zero friction to the BoxCollider2D here: alt text

To create the material, simply right click a folder in the project window and create a Physics Material 2D: alt text

Name it, change the friction value to 0, and apply it to your Box Collider 2D. This should make it so the cube doesn't "slow down to a stop".

Problem 2: "Falling Without Horizontal Velocity":

This problem is more difficult and could require some scripting.

While not the most robust system, to quickly make this work I would use an OnCollisionExit to tell when the cube has slid off an edge. At that moment I would set the velocity of the cube to zero so that it would just fall due to gravity without any horizontal velocity. Something like this:

 using UnityEngine;
 using System.Collections;
 
 public class FallImmediately : MonoBehaviour {
     private Rigidbody2D rb;
 
     // Use this for initialization
     void Start () 
     {
         // Get rigidbody so we can affect its velocity
         rb = GetComponent<Rigidbody2D>();    
     }
 
     void OnCollisionExit(Collision col)
     {
         // Remove all velocity so that only gravity affects it
         rb.velocity = Vector2.zero;
     }
     
 }

Simply attach this script to the ice block and you should be good to go.

While these are quick solutions to the problems you're having, you should definitely consider what Cherno has to say. Some design decisions should be made at this stage to help ease any frustrations you might have with this project in the future.

Good luck!


creatematerial2d.png (77.8 kB)
physicsmaterial.png (20.2 kB)
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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

I need to shoot a projectile in my 2D platformer in the opposite direction my player is dashing which can be in any direction the player points the joystick 2 Answers

projectiles not coliding with character 3 Answers

How do you make a 2D character jump at a fixed height no matter how much you press jump? 1 Answer

Allowing the player to draw something that turn in 2d shape with collison and solid color 1 Answer

Player falls through ground after adjusting pixels per unit of the players sprite 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