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 unity_exlS7hJ-hd9cbA · Aug 09, 2020 at 12:27 PM · scripting problem

Box wont collide with anything when picked up

Hello there, I'm making a Box pick up script and I'm having some issues with making the box collide with stuff. ( https://gyazo.com/21ddc772244ee938765d08a677df9c93 ) I want it to collide with the walls and other boxes. my code:

 using System.Collections;
 using System.Collections.Generic;
 using System.Data;
 using UnityEditor.Timeline;
 using UnityEngine;
 
 public class BoxScript : MonoBehaviour
 {
     public Transform Box;
     public Transform Player;
     public Transform BoxPosition;
     public Transform Map;
     public bool isHolding = false;
     public int maxDist = 5;
 
     private void OnMouseOver()
     {
         if (Input.GetMouseButtonDown(0))
         {
             if (isHolding == false)
             {
                 if (Vector3.Distance(Player.transform.position, Box.transform.position) < maxDist)
                 {
                     isHolding = true;
                     Debug.Log("Grab");
                     Box.GetComponent<Rigidbody>().isKinematic = true;
                     Box.position = BoxPosition.position;
                     Box.parent = BoxPosition;
                 }
             }
         }
     }
     private void Update()
     {
         if (isHolding == true)
         {
             if (Input.GetMouseButtonUp(0))
             {
                 isHolding = false;
                 Debug.Log("Drop");
                 Box.GetComponent<Rigidbody>().isKinematic = false;
                 Box.parent = Map;
             }
         }
     }
 }
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 Rasmus_Bonnesen · Aug 09, 2020 at 02:55 PM

Well I don't exactly know why this is happening(my best guess is that it has something with your player controller script to do), but I have a workaround to not make it visible that the cube clips through walls for the player.

1) Make a new Layer, and call it pickedUpCube or soemthing like that. 2)In your pickup script assign the layer to the cube everytime you pick up the cube.

 int idOfPickedUpLayer;    
 Box.gameObject.layer =  idOfPickedUpLaye

And when you drop the cube again, make sure the layer gets set back to whatever it was before.

 Box.gameObject.layer = 0;

3) On your main Player camera remove the "pickedUpCube" layer from its culling mask.

4) Add a new camera give it the same position your main player camera has, and make it a child object of it.

5) Set the Clear Flags value of the new camera to Depth only, and set its Culling Mask to the "pickedUpCube" layer, also make sure to remove all the othere layers from its culling mask.

If it doesn't work, try changin your Depth value on your main camera to 0 and 1 on your new camera.

Now the cube will probably still clip through walls but it won't be noticeable for the player anymore.

Hope this helps :)

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

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

Rigidbody set velocity on 1 axis without changing the others. 5 Answers

Need help In creating android game with UI buttons ?Please Help 1 Answer

Scripts not updating the material's shader properties 1 Answer

Flip between 2 states constantly C#? 1 Answer

In-Game Tutorial with special actions in special areas. (Shooter) 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