Hi,
Building a bike game, I use JavaScript to move the human figure's feet/shoes/legs with the pedals to be able to follow the bike pedals as they move around.. The Human model has a skeleton/mechanim in unity, this works fine (mostly) until I rotate the bike, then the feet stays in e.g. x axis.. you can see the behaviour on this youtube video:
[http://www.youtube.com/watch?v=_r9us5WSQfg&feature=youtu.be][1]
You can see that as I rotate the bike around the feet seem stay in one direction, not rotating with the bike. I have tried matching transform.rotation to pedals but this makes the mechanim go all crazy..maybe the code needs to go into FixedUpdate() ?
I have tried various things but not having much luck.
Here is the code I use to move the feet along with the pedals (two scripts, one for each foot):
**function Start () {
rightpedal = GameObject.Find("rightpedal");
rightlegup = GameObject.Find("UpLeg_R");
rightlegdown = GameObject.Find("LoLeg_R");
}
var rightpedal : GameObject;
var rightlegup : GameObject;
var rightlegdown : GameObject;
function Update () {
transform.position.y = rightpedal.transform.position.y +2;
transform.position.x = rightpedal.transform.position.x -3;
transform.position.z = rightpedal.transform.position.z-1;
//transform.position = rightpedal.transform.position;
//transform.rotation.z = rightpedal.transform.rotation.z;
//rightlegup.transform.eulerAngles.y = rightpedal.transform.eulerAngles.y;
//rightlegdown.transform.eulerAngles.y = rightpedal.transform.eulerAngles.y;
//rightlegup.transform.rotation.y = rightpedal.transform.rotation.y;
//rightlegdown.transform.rotation.y = rightpedal.transform.rotation.y;
//transform.rotation.x = rightpedal.transform.rotation.x;
//var dir = rightlegdown.transform.position - transform.position;
//dir = dir.normalized;
//rightlegdown.rigidbody.AddForce(dir * -450); //push forward
// rightlegdown.rigidbody.AddForce (Vector3.right * 10);
}**
I am sure I'm missing something really simple probably?
Any advise would be most apreciated.
Thanks,
Kim
[1]: http://www.youtube.com/watch?v=_r9us5WSQfg&feature=youtu.be
↧