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 pg · Jul 02, 2012 at 06:41 PM · animationjumpinteractionparkour

How to animate for object interaction?

Ok, so what I'm trying to do is make my player vault over an obstacle(like battlefield 3). It's in First Person, and I already have the legs, arms, fps controller, etc... Now I just don't know exactly how to approach the animation part of it. Should I just animate the arms and legs as if it were a loop? Or actually move the root in my 3d application, and make the player go over the obstacle in there? Me and my coder have been stuck on this for quite a while, and would really appreciate some help. If you need further examples, let me know :) We would also like to use this technique we're going to hear about to climb ladders. (if its the same process)

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
1

Answer by Matt-Downey · Jul 10, 2012 at 03:05 AM

If it's first person, there should be a lot less worries than for a third person.

Firstly, do you know about the camera trick where the player's gun and hand are placed in front of all other objects? http://answers.unity3d.com/questions/164787/gun-goes-through-a-wall.html

This will help you out a lot if you don't know about it, because you can just render the player extending his hand(s) downward as if trying to do a cat-vault. I don't think it would look that bad.

I'll be nice and give you a small parkour function for your coder that might end up helping you:

First: a picture is worth a thousand words

alt text

what you are seeing is a red/blue line. The red indicates that is not a space which the player can occupy, the blue indicates the space is free.

[edit5:] There is a very good space detector at the very bottom now.

 import System.Collections.Generic; 
 
 //this is the only variable you have to assign in the script
 var rigid : Rigidbody;
 
 //all values based on 2.0m player
 private var h1 : Vector3 = Vector3(0, 1.6,0); //maximum height above center of mass that the hand can reach
 private var h2 : Vector3 = Vector3(0,-0.55,0); // the lowest place checked (I do not want to check down to the feet, personally)
 private var height : float = 1; //the height of a crouching player (I want this to be prone in the future)
 private var h : float = h1.y - h2.y + height; //the distance after factoring in all those things
 
     class SortLedge implements IComparer.<float>
      {
         function Compare(o : float, t : float) //o == one, t == two
          {            
             if (o < t) return -1;
             if (o > t) return 1;
             return 0;
          }   
      }
     
     var alpha : RaycastHit[]; //rayCastAll going up
     var omega : RaycastHit[]; //rayCastAll going down
     var r : RaycastHit;  //ray
     var i : int;
      
     var d : float[]; //distances
     var s : float[]; //clone of distances
     var n : Vector3[]; //normals
     var p : Vector3[]; //points
     
     var length : int; //Tested: there shouldn't be any problems with default "1"-length arrays being returned
     
     var o : Vector3;
     var t : Vector3;
     
     function FixedUpdate()
      {
      alpha = Physics.RaycastAll(rigid.position + h2,Vector3.up,h,(1 << 0));
      omega = Physics.RaycastAll(rigid.position + h1 + height*Vector3.up,-Vector3.up,h,(1 << 0));
      
      length = alpha.Length + omega.Length + 2;
      
      d = new float[length];
      s = new float[length];
      n = new Vector3[length];
      p = new Vector3[length];
      
      d[0] = 0.0;
      n[0] = Vector3.up;
      p[0] = rigid.position + h2;
      
      i = 1;
      
      for(r in alpha)
      {
      d[i] = r.distance;
      n[i] = r.normal;
      p[i] = r.point;
      i++;
      }
      for(r in omega)
      {
      d[i] = h - r.distance; //must start from the opposite direction
      n[i] = r.normal;
      p[i] = r.point;
      i++;
      }
      
      d[i] = h;
      n[i] = -Vector3.up;
      p[i] = rigid.position + h1 + height*Vector3.up;
      
         s = d.Clone();
         System.Array.Sort(d,n, new SortLedge());
         System.Array.Sort(s,p, new SortLedge());
         
         i = 0;
      t = p[0];
      
      for(i = 1; i < length;i++)
      {
      o = p[i-1];
      t = p[i];
      
      if(i % 2 == 0) Debug.DrawLine(o,t,Color.red,0.019,false);
      else Debug.DrawLine(o,t,Color.blue,0.019,false);
      }
      
      //This is cool for debugging your sort function, otherwise it'll slow down my Lenovo crazily due to a stack overflow glitch, idc about reporting 
     // i = 0; 
     //    for (obj in p)
     //     {
     //        Debug.Log(String.Format("Name:{0}           Position:{1}", i, obj));
     //        i++;
     //        }
         }

From this information, you will be able to figure out the point of contact with the ledge you will be grabbing. The algorithm isn't done yet, but it creates negative spaces, if you will, that define occupied space (with zero overlap). To be fair it isn't that smart yet, but with a few adjustments, it will help more. After you sort the arrays, you look for a niche the player can fit into, based upon which you could theoretically find the spot (as a Vector3) that constitutes the ledge you are grabbing onto.

[edit:] and you could use that Vector3 for your animation, from what I know.

[edit2:] using something like this? (If you can't tell I'm mainly a 3D physics programmer, not much animation experience) http://docs.unity3d.com/Documentation/Manual/AnimationScripting.html#Procedural

[edit3:] a small package containing a newer version that is "smarter" link text

[edit5:] a larger package (160 lines) that is very smart (it can work with planes and complex objects finally). link text


mantledebugv2.txt (7.7 kB)
mantlev3.txt (7.9 kB)
Comment
Add comment · Show 1 · 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 pg · Jul 16, 2012 at 06:34 AM 0
Share

Thanks alot for this detailed information, I will let my coder take a look at this. Thanks again :D

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to have a character climb an obsticle automatically? 3 Answers

try to make my own character control with animation like- running, walk, idle. So need help and guideline how to do or start 0 Answers

Can I make animations snap to a frame? 1 Answer

How can ı activate my jump script only at animation 0 Answers

How do I get my jump animation to work? 1 Answer


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