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][1]
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.
{
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][2]
[edit5:] a larger package (160 lines) that is very smart (it can work with planes and complex objects finally). [link text][3]
[1]: http://i1122.photobucket.com/albums/l531/MattDWNY/DetectingOpenSpaces.png
[2]: /storage/temp/1977-mantledebugv2.txt
[3]: /storage/temp/2126-mantlev3.txt
↧