Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How can this be done?

Discussion in 'Scripting' started by pizzaboy13, Mar 1, 2020.

  1. pizzaboy13

    pizzaboy13

    Joined:
    Mar 6, 2019
    Posts:
    18


    I’m trying to build a demo for a game that is like Nintendogs, where you interact with virtual animals. You pat these animated creatures, stroke their backs, etc.

    Let’s say I have virtual hands, how can I have them transverse across the animals mesh? Keep in mind these animals will be animated.

    For example, if I click a dogs head, the hand will move towards the head, if I drag the hand up and down, the hand will move towards those position, keeping close to the mesh and respecting the animal’s head shape

    I already have the IK set up, what I need is to know:
    1.) where in world space the target is
    2.) hands transverse through the mesh
    3.) the ideal rotation for the hands

    Just to be clear, just finding the position of the target in world space is not enough, the hand needs to move across the mesh. For example, Let’s say I click a cylinder, the hand goes towards the cylinder, if I hold the click down and move my mouse, the hands will move across its surface including moving towards areas concealed from the camera

    any ideas?
     
  2. pizzaboy13

    pizzaboy13

    Joined:
    Mar 6, 2019
    Posts:
    18
    I just had an idea, in super mario galaxy, mario can walk across planets. I think it’s done with rigid bodies or kinematic body I’m not sure, I can turn the ik target to a physics body when I am close to the position, and use gravity to keep it on the mesh. I’m going to try this out but I’m sure there is a better solution
     
  3. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,556
    Indeed, you should enable physics and rigidbodies. That way, the objects cannot move inside each other.
     
  4. pizzaboy13

    pizzaboy13

    Joined:
    Mar 6, 2019
    Posts:
    18
    Is there another way to do it? I don't like using the physics system if I can avoid it as it can be buggy and expesive
     
  5. davidnibi

    davidnibi

    Joined:
    Dec 19, 2012
    Posts:
    426
    Use a raycast from the hand - align the hand towards each normal on the mesh, so it’s always perpendicular.
    Obviously you would avoid concave surfaces on the dog always, but they don’t have many of them!