Hi, I have a question about physic animation…
Yesterday, I took a part (the one which makes sure the foots are always in contact with the terrain mesh) of the “Heron”-code (from Island-Demo) and attached it to the robot (from fps-tutorial). When I start the game, th robots legs are in the ground and when I attach the same code to a ragdoll, it’s legs are pulled into the ground too…
This is the code:
var leftKnee : Transform;
var leftAnkle : Transform;
var leftFoot : Transform;
var rightKnee : Transform;
var rightAnkle : Transform;
var rightFoot : Transform;
private var player : Transform;
private var terrain : TerrainData;
function Start()
{
forward = transform.forward;
obj = GameObject.FindWithTag("Player");
player = obj.transform;
myT = transform;
terr = Terrain.activeTerrain;
if(terr)
terrain = terr.terrainData;
}
function LateUpdate () // leg IK
{
rightHeight = terrain.GetInterpolatedHeight(rightFoot.position.x / terrain.size.x, rightFoot.position.z / terrain.size.z);
rightNormal = terrain.GetInterpolatedNormal(rightFoot.position.x / terrain.size.x, rightFoot.position.z / terrain.size.z);
leftHeight = terrain.GetInterpolatedHeight(leftFoot.position.x / terrain.size.x, leftFoot.position.z / terrain.size.z);
leftNormal = terrain.GetInterpolatedNormal(leftFoot.position.x / terrain.size.x, leftFoot.position.z / terrain.size.z);
if(leftHeight < rightHeight)
{
transform.position.y = leftHeight;
leftFoot.rotation = Quaternion.LookRotation(leftFoot.forward, leftNormal);
leftFoot.Rotate(Vector3.right * 15);
raise = (rightHeight - leftHeight) * 0.5;
rightKnee.position.y += raise;
rightAnkle.position.y += raise;
rightFoot.rotation = Quaternion.LookRotation(rightNormal, rightFoot.up);
rightFoot.Rotate(-Vector3.right * 15);
}
else
{
transform.position.y = rightHeight;
rightFoot.rotation = Quaternion.LookRotation(rightNormal, rightFoot.up);
rightFoot.Rotate(-Vector3.right * 15);
raise = (leftHeight - rightHeight) * 0.5;
leftKnee.position.y += raise;
leftAnkle.position.y += raise;
leftFoot.rotation = Quaternion.LookRotation(leftFoot.forward, leftNormal);
leftFoot.Rotate(Vector3.right * 15);
}
transform.position.y += 0.1;
}
Now, I’m wondering what I could have done wrong… :?
Should the legs have “rigidbody” attached to them?
Or do they need colliders?
Any help would be great!
Hi, I have a question about physic animation…
Yesterday, I took a part (the one which makes sure the foots are always in contact with the terrain mesh) of the “Heron”-code (from Island-Demo) and attached it to the robot (from fps-tutorial). When I start the game, th robots legs are in the ground and when I attach the same code to a ragdoll, it’s legs are pulled into the ground too…
Well, that code is pretty much made specifically for the heron and for the Island demo. It assumes that you are on a terrain, that the terrain is placed a specific place, and it also has some lines that are specific to how the bones in the heron are aligned, it seems. Put simply, it was not designed to be applied to other characters, or other scenes.
(By the way, it has nothing to do with physics.)
Also note that the heron’s legs are actually adjusted in a rather crude way that simply breaks the legs to make them fit, as can be seen in the image in this post:
http://forum.unity3d.com/viewtopic.php?p=57287#57287
oh, ok thanks runevision…
I didn’t know that the legs get “broken”, so I thought it would be physic animation… :?
But how to create real physic animations?
oh, ok thanks runevision…
I didn’t know that the legs get “broken”, so I thought it would be physic animation… :?
But how to create real physic animations?
What do you mean by physic animations exactly? What is it that you want to achieve?
How to best go about it depends a lot on what kind of results you need or what kind of problem you want to solve.
I want the character’s feet to always touch the ground when his feet should touch the ground (when he makes a step).
I wrote a (very) short code myself… and it’s working perfectly!
var footHeight = 0.2;
var hitPos : Transform;
var AnimatePhysics : boolean = false;
var MaxGroundDist : Transform;
var speed = 1.5;
function Update () {
var hit : RaycastHit;
if (Physics.Linecast (transform.position, MaxGroundDist.position, hit)) {
if (AnimatePhysics == false) {
AnimatePhysics = true;
}
hitPos = hit.transform;
}
else {
AnimatePhysics = false;
}
if (AnimatePhysics == true) {
if (transform.position.y > hitPos.position.y) {
transform.Translate(0, -speed * Time.deltaTime, 0, Space.World);
}
if (transform.position.y < hitPos.position.y) {
transform.Translate(0, speed * Time.deltaTime, 0, Space.World);
}
if (transform.position.y == hitPos.position.y) {
transform.Translate(0, 0, 0);
}
}
}
It moves the character’s feet (on the y-axis) to the ground if they are near to it.
Very simple…
ok, that sucks: :shock:
Not really, but Ijust discoverd that unity created exactly what I needed…
oh ok…
This project is great!