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 DubstepDragon · Jul 09, 2013 at 03:24 PM · collisiondetectiondungeon

Manual Collision Detection...

I have a basic cube that moves a certain space when a movement key is pressed. However, since I am using direct Transform variables, there is no Player Controller involved, therefore no collision. However, what I intend to do is create a surface that the player cannot move passed. How can this be achieved? I already thought of an idea that involves recording the previous position and resetting the current position as the previous position every time the player hits the wall. But that is not effective... What are your views? Thanks in advance!

Comment
Add comment · Show 7
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 swyrazik · Jul 09, 2013 at 03:30 PM 1
Share

Why not use Rigidbodies and CharacterControllers?

avatar image DubstepDragon · Jul 09, 2013 at 03:36 PM 0
Share

$$anonymous$$y script is set up the way I already set it up - I am not in the mood to write one that uses Character Controllers :P Sorry, but I am lazy and a little bit of a program$$anonymous$$g newbie - I work with Java, and not UnityScript, and I am kinda new to Unity3D.

avatar image swyrazik · Jul 09, 2013 at 03:43 PM 1
Share

I don't think adding a Rigidbody for detecting collisions will be more time consu$$anonymous$$g than implementing a manual collision detection.

avatar image DubstepDragon · Jul 09, 2013 at 03:57 PM 0
Share

Yeah, but only problem is, I have attached a Rigidbody, but my movement still goes through walls, because as I said, my script is designed to move a direct amount of spaces to the desired direction, and is not intended to implement Rigidbody collisions, so my character ends up juttering annoyingly, and even if I freeze all rotation, it still penetrates walls.

avatar image AlucardJay · Jul 09, 2013 at 06:27 PM 1
Share

If you want collisions, don't modify the transform position variable directly. Use a rigidbody or a character controller. This is the best (and probably only) advice you will get.

There is no easy solution. The easy way is to use a rigidbody, and not modify the transform variable directly. If you tell a transform to position somewhere, it will, no matter what the collider setup.

As stated above, writing a complex collision detection system is just making a huge amount of work for yourself. Using a rigidbody and modifying the velocity variable (or a character controller with move) is much easier.

Show more comments

2 Replies

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

Answer by SchecterKing · Jul 09, 2013 at 08:44 PM

Try to do something like what I explained here with the transparent boxes and using them as triggers in code. http://answers.unity3d.com/questions/489848/how-to-improve-the-performance-of-removing-trees-d.html

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
avatar image
0

Answer by Alturis2 · Dec 04, 2013 at 03:36 AM

Funny I was just trying to get pretty much the exact same thing going. I briefly attempted to use rigid bodies but that is just way more beef than the problem requires. Physics.RaycastAll is the answer I believe.

Try this:

 // Update is called once per frame
 void Update () 
 {
     bool up = Input.GetKeyDown(KeyCode.W);
     bool right = Input.GetKeyDown(KeyCode.D);
     bool left = Input.GetKeyDown(KeyCode.A);
     bool down = Input.GetKeyDown(KeyCode.S);

     Vector3 move = new Vector3( 0, 0, 0 );
     Vector3 nmlMove;

     if (up)
         move.z += 1;
     if (right)
         move.x += 1;
     if (left)
         move.x -= 1;
     if (down)
         move.z -= 1;

     if ( move.magnitude > 0 )
     {
         nmlMove = move;
         nmlMove.Normalize();

         RaycastHit[] hits;
         hits = Physics.RaycastAll( transform.position, nmlMove, move.magnitude );

         if ( hits.Length == 0 )
             transform.Translate( move );
     }
 }
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

20 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

Related Questions

Trying to make a procedurally generated dungeon (3D), but rooms won't spawn 1 Answer

chronological order of collision to give a winner unity 2d 4.3 1 Answer

Collision Enter one of the objects ? 1 Answer

Weapon System with collide detection (Helps with script pls)!!! 0 Answers

How to detect when an object goes past (so it looks like it touches) a UI element. 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