codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Need some help with javascript code in Unity!  marklubbers88 at 21:35 on Monday, March 22, 2010
 

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. Which I don't want...

So my question is if maybe you can help me out with my code. Here it is:






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]);
}





If you want to know what you can do with Unity3d, you can find an overview here:
http://unity3d.com/support/documentation/ScriptReference/index.html


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

  Re: Need some help with javascript code in Unity!  amery buck at 12:55 on Friday, April 30, 2010
 

Ground shaking content i get form your blog. Very nice post about code in Unity. Thanks for your beneficial information about testking E20-520, testking HP0-S24 and testking 646-276 certifications. These are the best certifications in the world.








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: How work this reusable form validation script ?
•  Re: IFRAME Problem: Scrollbar disappears if Resize IE window
•  Re: Print .doc file from the website using System.Diagnostics.Process
•  Re: Add an OnChange event to an ASP page
•  Re: Submit multiple forms with one button
•  Re: execute linux commands in perl script
•  Re: Print and print preview file on the website without using the File - Print on the IE
•  Argh, Javascript + Forms and me = DISASTER!
•  Need javascript code to identify non-searchable PDF


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2010