Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by GravitySpec · Feb 15, 2011 at 05:04 PM · collisiontexturemeshplanetexturecoord

Get Texture Coordinates from a Plane when a Mesh or object Intersects/Collides

I'm trying to make a "Worms" type game where an object falls from above and impacts a plane with a texture and causes a portion of the terrain to erase when it contacts a non-transparent part of the texture.

Code I'm currently trying to use can be found here: http://www.pasteit4me.com/2277018

alt text

Imagine the surrounding black box is the plane where the image texture ends and the rest is just transparent texture. The red box is the cube mesh that intersects the plane from above. Falling onto it along the same Z axis.

So far I'm able to use Raycasting to get the texture coordinates using mouse input through a script attached to the plane's Update() method:

RaycastHit hit;
if (Physics.Raycast (Camera.main.ScreenPointToRay (Input.mousePosition), out hit))
     return hit.textureCoord;

This works fine as a texture eraser using the mouse, but when I try to use a colliding object instead (simple cube), I can't seem to get the texture coordinates (come up zero), even though a collision is being registered. The plane is set to be a trigger, so I'm trying to use OnTriggerStay() to do a raycast from the colliding object's position.

I'm thinking I'm somehow not properly translating the position of the cube in space to planes texture. Though I thought that's what the RayHitcast.textureCoord is supposed to represent.

Please let me know if any clarifications are in order. Thanks!

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

2 Replies

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

Answer by GravitySpec · Feb 18, 2011 at 02:49 AM

With some help from mike_mac on #unity3d IRC I was able to solve my issue.

The Raycast was hitting the cube itself instead of the plane. So I created a layer and added the bomb prefab to that layer, then updated the Raycast to check all layers except the weapon layer (in this case was layer 8).

So the Raycast looked like this:

var hitpoint = other.transform.position + Vector3.forward;
if (!Physics.Raycast (hitpoint, Vector3.back * 2.0f, out hitter, 5.0f, ~(1<<8)))

I'll explain the ~(1<<8) as it was the first time I really saw this used. Where ~ is a bitwise NOT and << is a bitwise left shift. So 1<<8 would be just layer 8 and ~(1<<8) is all layers except 8.

Augment the script from the question and this will be complete. :)

Enjoy!

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 destrozates · Jul 10, 2018 at 06:49 PM

Sorry Gravity, I know it has been a long time ago since you posted this, but could you show me the code used to erase the portion of the terrain? Your link is not working. Thanks

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

1 Person is following this question.

avatar image

Related Questions

Making textures stop bending 0 Answers

Generate collision mesh from 2d texture? 0 Answers

Collision detection problems with plane + 2D Sprites 0 Answers

Tile Texture Smearing 1 Answer

Mesh separating from CharacterController 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