Need some help with javascript code in Unity3d!

Hello everyone,

at the moment I’m working on writing a code for a interactive project. This project is made out of a 3dmodel, that I made in 3dsmax. I want to animate this model, and make it respond to an actual person by motion detectors and a camera that works together with a javascript code.

I’m trying to make this animated model walk to different coordinates. When doing so I have two different choices, either my object ‘slides’ to a location, or the object does a ‘walkcycle’ which remains in place. (So the background moves.) What I want, ideally, is a sliding walkcycle. This has to have a place where it has to stop, so it doesn’t move out of the picture. (I hope this still makes some sense.)

I am now working in Unity3d. When the webcam receives a value above ‘200’, the walking cycle begins. With the value is below 200 my object doesn’t move.

My problem now is, that when the webcam gives these values above 200, the values don’t go down anymore. My object gets stuck in it’s animation and keeps repeating it.

My question is if maybe you can help me out with my code. This is the code:

public var RemoteIP : String = “127.0.0.1”;
public var SendToPort : int = 9000;
public var ListenerPort : int = 8000;
public var Controller: Transform;
private var handler : Osc;
private var sigX : int = 160;
private var sigY : int = 120;

public function Start ()
{
var udp : UDPPacketIO = GetComponent(“UDPPacketIO”);
udp.init(RemoteIP, SendToPort, ListenerPort);
handler = GetComponent(“Osc”);
handler.init(udp);
handler.SetAddressHandler(“/X-as”,X);
handler.SetAddressHandler(“/Y-as”,Y);
}

Debug.Log(“Start”);

function Update ()
{
var go = GameObject.Find(“model”);
go.animation.wrapMode = WrapMode.Once;
go.animation[“idle”].wrapMode = WrapMode.Loop;

go.animation.Play(“idle”);

if(sigX > 200) {
go.animation.Play(“walk”);
}
}

public function X (oscMessage : OscMessage) : void
{
Debug.Log(Osc.OscMessageToString(oscMessage));
sigX = (oscMessage.Values[0]);
}

public function Y (oscMessage : OscMessage) : void
{
Debug.Log(Osc.OscMessageToString(oscMessage));
sigY = (oscMessage.Values[0]);
}

Anyways, sorry for the long message and I really hope you can help me out. Thanks in advance!

Hope to hear from you guys!

Mark

you could try putting an else bit to this bit of code

if(sigX > 200) { 
go.animation.Play("walk"); 
}

if not maybe try this instead of the code above

while(sigX > 200) {
go.animation.Play("walk"); 
}

i have absolutely no idea if either of these would work but it’s worth a try!