Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Use dynamic mesh to climb the wall ?

Discussion in 'Scripting' started by LuXuan444, Aug 7, 2014.

  1. LuXuan444

    LuXuan444

    Joined:
    Jan 18, 2013
    Posts:
    19
    Hi, everyone.
    I'm not a native English speaker, so sorry for reading my poor English first.

    I have a question which I have not clue how to do it.
    I'm trying to create a dynamic mesh that can climb the wall just like the gif I posted.
    In the gif, I use shadow to simulate the effect.

    Can anyone tell me if it's possible to use the dynamic mesh making this kind of climbing effect?
    Or if there're another better ways to do it?

     
  2. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,679
    If it is just a flat object you want to climb the wall then take a look at the decal systems available on the Asset Store.
     
  3. LuXuan444

    LuXuan444

    Joined:
    Jan 18, 2013
    Posts:
    19
    Thanks for the advice!
    It seems like a way to do it.
    I'll take a try.
     
  4. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    How about a spot light with a cookie?
     
  5. LuXuan444

    LuXuan444

    Joined:
    Jan 18, 2013
    Posts:
    19
    I've a little tried after seeing your reply,
    but it seems the cookie can only have one color.
    It doesn't meet what I want.
    I want a flat object with texture and collider.

    Still thanks for your advice :)
     
  6. LuXuan444

    LuXuan444

    Joined:
    Jan 18, 2013
    Posts:
    19
    The decal systems is great!
    But I still suffer some problems.

    The decal systems use the bounding box to project texture.
    It will create a whole mesh, so if I use the mesh collider, the whole mesh will be detected as collider.
    It's weird if the texture's transparent parts is detected.

    If there's any way to only detect the texture's non transparent parts?

    ---------------------------------------------------------------------------

    And the other thing is, when I'm trying to calculate the normals to get the best rotation of the decals.
    I found that contact points of collision can help me, but I can't just use the OnCollisionEnter.
    So I have to use OnTriggerEnter, but with this method I can't use contact points.

    Because I'm using the decal systems dynamically, so I need to dynamically find the correct rotation of decal to project texture right.

    Does someone has any idea how to do it?
     
  7. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Could you share a few more details about your actual use case?

    Same here. I need a few more information to understand the use case.
     
  8. LuXuan444

    LuXuan444

    Joined:
    Jan 18, 2013
    Posts:
    19
    Sorry for my bad description.

    The problem of collider is I only want to detect specific area (like the black part in the image), but decal project whole mesh with texture so it's not possible to use mesh collider.
    I want to ask if there is another way to do it?



    The second question is I need to dynamically use decal in the game just like the gif. I post in the #1.
    So I have to dynamically rotate decal object.

    For example, if I want to use decal to climb the wall, decal need to rotate if it touchs another mesh (like the image).
    I try to get the normals of two planes and calculate the best angle to rotate,
    but I didn't find the proper way to accomplish.
     
  9. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I didn't make it clear enough. My question was, why you need it. Depending on your case, you may use exactly this solution, but with a few tricks.
    If you want a tighter mesh, you need to perform more cuts to achieve the circular shape. I don't know which solution you are using, but it is most likely quite some work to get that.

    The effect you are showing there is different. It is not one projection, but two. One onto the floor and another one onto the wall. The difficulty would be to find the correct position for that.
    Using just one projector, will most likely be simpler. As you got the hit point, you may go backwards for a certain amount. Either backwards along the ray or the normal. Now from the position, I would make further raycasts towards the ground of the projector. At least towards all the corners. Now you have the original ray and the corner ones. You may use the normals of them to calculate the rotation. In order to get smoother behavior over time, you need to give each normal a weight. The closer the hit point to the origin, the higher the weight. Now take the sum of those weighted normals and normalize it. This should give you a relatively stable basis. If you increase the number of raycasts, you will most likey also get a more stable result.
     
  10. LuXuan444

    LuXuan444

    Joined:
    Jan 18, 2013
    Posts:
    19
    Oh! I misunderstood it. :P

    I want to use this as my main character's skill.
    When player use it, they can become an object similar to the

    shadow and move like the shadow to every way, even ceiling.
    So it will only have one object like this in the scene.

    And the solution I am using is the "Simple decal system" :http://u3d.as/6gt
    It is enough for me to realize how decal works.
    The way it creates decal is basically like this thread :
    http://blog.wolfire.com/2009/06/how-to-project-decals/

    I'm not sure if it works just like the system, "Decal System Pro", your team designed.

    I'm not really understood what did you mean two projections.
    This system only have one box projector.
    The meshs onto the wall and floor are the mesh it crops.

    And the further raycasts is like this?
    [Blue is the original ray, green is the cornor rays.]



    Anyway, thanks for your patient to reply me. :)
     
  11. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    What do you mean with "When player use it"? If it needs to be selectable with the mouse, you may use the raycast hit information to check whether an invisible or visible part on the texture was clicked.

    My team consists of myself :) . The underlying ideas are identical.

    The gif you are showing looks as if two projections take place. One straight down and the other straight onto the wall.

    I would try to avoid any upward raycast. But at the end you just need something that is believable.
     
  12. LuXuan444

    LuXuan444

    Joined:
    Jan 18, 2013
    Posts:
    19
    It's not being selectable with mouse.
    When player input a key to use this skill, they will become the object similar to the shadow.
    Then uses the Horizontal and Vertical Input to move this object.

    I forgot to tell another mechanics in this game. :|
    The collider is used to detect whether any light hit the black part.
    If hit, the player will get hurt.
    That's why I only need to detect visible part on the texture.

    Wow! I thought it was created by a team. XD

    Oh! I got it. Sorry that I didn't explain properly.

    Thanks for the tips! I haven't thought about this.
     
  13. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Instead of using the collision detection directly, you may consider to use a sphere cast in the direction of the projection, to find the touching objects. For this kind of situation it is often needed to find creative solutions.
     
  14. LuXuan444

    LuXuan444

    Joined:
    Jan 18, 2013
    Posts:
    19
    After a few days of trying.
    I found that I just need to attach one capsule collider and automatically adjust it for some specific angles.
    Although the result is not very precise, it's still enough.

    Before this I alway wants to get the collider as precise as possible.
    I thought I just forgot the KISS principle. :P

    -------------------------------------------------------------

    Using the raycast to get normals is work pretty good, but still have some problems.
    In some corners (like the picture below), the raycast can't get normals correctly.
    I have tried to create some rays onto the cube's border and shoot to the original ray's point, but the whole decal object will rotate crazily.

     
  15. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
  16. LuXuan444

    LuXuan444

    Joined:
    Jan 18, 2013
    Posts:
    19
    Thanks for your advice. :)
    I've tried to use a projector before,
    but it can't project onto transparent objects.

    The picture shows the different between projector(left) and decal(right) when project onto the transparent object.
     
  17. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Download Unity's built-in shaders, pick the transparent one that you are using, give it a new name, change it such that it doesn't ignore projectors. That should do the trick.
     
  18. LuXuan444

    LuXuan444

    Joined:
    Jan 18, 2013
    Posts:
    19
    Okay, I changed it so it doesn't ignore projectors,
    but it actually became more weird ......



    I think the decal system is almost meet what I needed,
    but in some angles such like the picture I post in #14 is still need to find a way to fix it.
     
  19. LuXuan444

    LuXuan444

    Joined:
    Jan 18, 2013
    Posts:
    19
    I found an easy but not very good way to do this.
    Putting a lot of box triggers at every corners and places where the player will go.
    The decal will rotate angle or do another things according to the trigger it stays.

    It works quite great, but it spends too much time on putting these box triggers.
    So I might need to write an editor to make it easier.

    Anyway, thanks for all you guys help. :)