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 /
  • Help Room /
avatar image
0
Question by oscarklm · May 28, 2017 at 11:03 AM · 2d-platformerplayer movement

2D Platformer - Sinking into colliders & bumping over tilemap

Hey fellow Unity Developers, hope you're having a nice day!

I'm currently developing a 2D Platformer and i have this issue with my player sinking into colliders and also hitting bumps when moving over an platform made up from a tileset.

So my question is, how is the best way to do a 2D Platformer Controller, and handle collisions - i'm still fairly new to Unity and C# so would love to learn about new ways to achieve this.

Here is my PlayerController:

 using System.Collections;
 using System.Collections.Generic;
 using Com.LuisPedroFonseca.ProCamera2D;
 using UnityEngine;
 
 public class PlayerController : MonoBehaviour {
 
     [Header("Player Movement")]
     public LayerMask playerMask;
     public float maxSpeed = 7f;
     public float jumpTakeOffSpeed = 7f;
     public bool canMoveInAir = true;
     public Transform groundCheck;
 
     public bool grounded;
     private float playerInput;
     private Vector2 velocity;
     private Rigidbody2D rb2d;
     private float groundCheckRadius = 0.2f;
 
 
     void OnEnable()
     {
         rb2d = GetComponent<Rigidbody2D>();
         ProCamera2D.Instance.AddCameraTarget(transform);
     }
 
     void Start () {
 
     }
 
     void FixedUpdate()
     {
 
         velocity = rb2d.velocity;
         grounded = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, playerMask);
         Debug.DrawLine(transform.position, groundCheck.position, Color.red);
 
         Move(Input.GetAxis("Horizontal"));
 
         if (Input.GetButton("Jump"))
         {
             Jump();
         }
     }
 
     public void Move(float horizontalInput)
     {
         if (!canMoveInAir && !grounded)
             return;
 
         velocity.x = horizontalInput * maxSpeed;
         rb2d.velocity = velocity;
     }
 
     public void Jump()
     {
         if (grounded && velocity.y == 0)
         {
             rb2d.AddForce(Vector2.up * jumpTakeOffSpeed, ForceMode2D.Impulse);
         }
     }
 
     public void Die()
     {
         Destroy(gameObject);
     }
 
 }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ismaelnascimento01 · May 28, 2017 at 12:56 PM

Use Collider 2D and Rigibody2D

Comment
Add comment · Show 8 · 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
avatar image oscarklm · May 28, 2017 at 01:03 PM 0
Share

I have attached my code, you can see that i'm already using a Rigidbody2D and just to confirm i am using only 2D colliders.

avatar image ismaelnascimento01 oscarklm · May 28, 2017 at 01:08 PM 0
Share

check if option 'is Trigger' have active in collisors

avatar image oscarklm ismaelnascimento01 · May 28, 2017 at 01:18 PM 1
Share

Amount of gravity on my Player is set to 3

Show more comments
avatar image ismaelnascimento01 · May 28, 2017 at 01:21 PM 0
Share

Do you check 'Order in layer' ?

avatar image oscarklm ismaelnascimento01 · May 28, 2017 at 01:22 PM 0
Share

What do you mean?

avatar image ismaelnascimento01 oscarklm · May 28, 2017 at 01:24 PM 0
Share

Check link: https://docs.unity3d.com/$$anonymous$$anual/class-SpriteRenderer.html And the size of the collider is according to the sprite

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

106 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

Related Questions

How To Do Basic 2D Movement? 1 Answer

why does my 2d platformer lags? 1 Answer

Help with a roll effect 2D 0 Answers

If player hits certain X value in opposition to Camera, shift camera question. 0 Answers

Unity52D - Player Jump Bug 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