Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 MilkX5 · Feb 12, 2013 at 01:14 AM · collisionphysicscolliderstop-downdungeon

Wall collisions for a top-down game

Hi! I'm trying to make a game like the old-school top-down Zelda games, but I can't figure out how to setup the collision on my character. I'm using a regular cube just to practice with, but I plan to make my game in 2D.

I've already tried rigidbodies on my character. It stops it from going any further, but it makes it really jumpy when I hit something and keep pressing on the same button. Colliders I'm not exactly sure how to code it so I can have nice smooth stopping like in Zelda. Which is best for my situation and can anyone please give me some starter code (preferably JavaScript)? I've spent 3 days researching this topic on Google, Unity Forums, Unity Answers, and Unity Wiki. I would really appreciate any help! Thanks so much!

BTW here is the original code for my main character var speed : float = 5.0;

 function Update () 
 {
     var transH : float = Input.GetAxis("1P Horizontal") * speed * Time.deltaTime;
     var transV : float = Input.GetAxis("1P Vertical") * speed * Time.deltaTime;
     
     transform.Translate(transH, transV, 0);
 }
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
Best Answer

Answer by Dan Miller · Feb 12, 2013 at 02:26 AM

Try adding a Character Controller to your player. Then change your above code to the following

 function Update () 
 {
     var transH : float = Input.GetAxis("1P Horizontal") * speed * Time.deltaTime;
     var transV : float = Input.GetAxis("1P Vertical") * speed * Time.deltaTime;
  
     GetComponent(CharacterController).Move(transH, transV, 0.0f);
 }


Then by having just a box collider on the walls with Is Trigger unchecked should give you the collision results you are looking for.

Comment
Add comment · Show 9 · 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 MilkX5 · Feb 19, 2013 at 02:38 AM 0
Share

Unity gives me an error on your code stating:

The best overload for the method 'UnityEngine.CharacterController.$$anonymous$$ove(UnityEngine.Vector3)' is not compatible with the argument list '(float, float, int)'.

BTW sorry for the late response. I've been insanely busy this week

avatar image Dan Miller · Feb 19, 2013 at 02:57 AM 0
Share

putting GetComponent(CharacterController).$$anonymous$$ove(transH, transV, 0.0f);

should fix that error. I've edited and corrected the original post.

avatar image MilkX5 · Feb 20, 2013 at 11:10 PM 0
Share

still the same issue :/

avatar image MilkX5 · Feb 23, 2013 at 11:45 PM 0
Share

I fixed the problem, but I'm still not getting any collisions

avatar image Dan Miller · Feb 24, 2013 at 12:10 AM 0
Share

do the walls you wish to collide with have box colliders on them and is the 'is Trigger' box on them unchecked?

Show more comments

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

10 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

Related Questions

More realistic physics? 0 Answers

Colliders going through Colliders? 1 Answer

[2Dplatformer][Problem] When the player closes to the enemy, the enemy pass through the colliders 0 Answers

Colliders not Colliding when FPS are to low 1 Answer

Level colliders reducing acceleration 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