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 /
  • Help Room /
avatar image
0
Question by raniceyue · Mar 22, 2021 at 03:39 PM · vrcollidersoverlappingdigging

Changing mesh filter component of prefab when other object stops overlapping

I am trying to create a VR game, where one part of the game consists of the player digging the soil to create a hole

I have created a dirt mound prefab, and in order to simulate the dirt getting reduced after the player digs it, I am currenlty thinking of doing this:

  • When the collider of the spade overlaps with the dirt mound, do nothing, i.e. the spade should be able to pass through the dir mound

  • When the collider of the spade stops overlapping with the dirt mound, change the mesh of the dirt mound to a model of the dirt mound that is reduced.
    Currently, the mesh collider of the dirt mound is set as Convex = true, isTrigger = true

    This is the code I have so far for the dirt mound

        public class Soil : MonoBehaviour {
             public Mesh hole_50;
             public Mesh hole_100;
             private float digging_state = 0;
     
         // Start is called before the first frame update
         void Start()
         {
             
         }
     
         // Update is called once per frame
         void Update()
         {
             
         }
     
         void OnTriggerEnter(Collider other)
         {
              // Do nothing
         }
     
         void OnTriggerExit(Collider other)
         {
             if (digging_state == 0f)
             {
                 this.gameObject.GetComponent<MeshFilter>().mesh = hole_50;
                 digging_state += 0.5f;
                 Debug.Log("Digging state from 0 to " + digging_state);
             }
     
             
             if (digging_state == 0.5f)
             {
                 this.gameObject.GetComponent<MeshFilter>().mesh = hole_100;
                 digging_state += 0.5f;
                 Debug.Log("Digging state from 0.5 to " + digging_state);
             }
         }
     }
    
    

Basically, I have 2 Mesh variables that keep track of the different meshes to load when the state of the dirt mound changes.

  • For state = 0, it means that the dirt mound is not dug yet

  • For state = 0.5, it means that the dirt mound is slightly dug

  • For state = 1.0, it means that the dirt mound is completely dug and there is a hole in it
    Here is an image with the dirt mounds of different states alt text

    For some reason, when I test the code out, the moment the spade even touches the dirt mound, the dirt mound jumps to the last state with the hole in it, and I can't figure out why.

    Is there any better way to simulate digging soil?

dirt.png (22.0 kB)
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 rh_galaxy · Mar 22, 2021 at 04:56 PM

digging_state will go from 0 to 1.0 the first time in OnTriggerExit().

When 0 you add 0.5, then if 0.5 it will become 1.0 because of:

 if (digging_state == 0.5f)
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

200 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

Related Questions

SteamVR Throw/fling object with another object 0 Answers

How do you stop SteamVR Player from colliding with a car? 0 Answers

How could I get if two colliders in different positions have been triggered by two different objects? 0 Answers

Graphics issue with the Unity 2017.1 native Google cardboard sdk 0 Answers

My collisions won't work whenever I pick it up with the XR Toolkit 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