- Home /
Question by
Oobi23 · May 26, 2013 at 01:46 AM ·
animationraycastcharactercontrollerraycastingcharacter movement
How to make char animation idle
Hi there, I am trying to make my character idle without animating when no movement buttons are pressed. I am just not sure about how to go about this. I am using raycast and this is my coding.
private var insideObject:Transform;
private var okToMove:boolean;
private var showingMission:boolean;
private var showingMission2:boolean;
function Start(){
insideObject=transform.Find("Capsule");
okToMove=true;
showingMission=false;
showingMission2=false;
}
function Update () {
if(okToMove){
//Debug.Log(insideObject.rotation.eulerAngles);
var dwn = transform.TransformDirection (Vector3.down);
var fwd = transform.TransformDirection (Vector3.forward);
var bk = transform.TransformDirection (Vector3.back);
var r = transform.TransformDirection (Vector3.right);
var l = transform.TransformDirection (Vector3.left);
var forwardPos:Vector3=transform.position + fwd;
var backwardPos:Vector3=transform.position + bk;
var rightPos:Vector3=transform.position + r;
var leftPos:Vector3=transform.position + l;
var hit:RaycastHit;
Debug.DrawRay(forwardPos,dwn,Color.green,5.0);
//move front
if (Input.GetKeyDown(KeyCode.UpArrow)) {
if (Physics.Raycast (transform.position, fwd, hit,1)) {
print ("There is something in front of the object!");
if(hit.collider.gameObject.tag!="Push"){
if (hit.collider.gameObject.tag == "endGame"){
Application.LoadLevel(0);
}else{
transform.position += Vector3.up;
}
}
else{
print ("Push!");
hit.collider.gameObject.transform.position += Vector3.forward;
transform.position += Vector3.forward;
}
}else{
Debug.Log("nothing in front");
if (Physics.Raycast (forwardPos,dwn, 11)) {
transform.position += Vector3.forward;
//did we move to an empty space ?
if (!Physics.Raycast (transform.position,dwn, .5)) {
okToMove=false;
InvokeRepeating("dropDown",1.0,1.0);
}
}
}
insideObject.rotation.eulerAngles.y=0;
}
//move back
if (Input.GetKeyDown(KeyCode.DownArrow)) {
if (Physics.Raycast (transform.position, bk, hit,1)) {
print ("There is something in front of the object!");
if(hit.collider.gameObject.tag!="Push"){
transform.position += Vector3.up;
}else{
print ("Push!");
hit.collider.gameObject.transform.position += Vector3.back;
transform.position += Vector3.back;
}
}else{
Debug.Log("nothing in front");
if (Physics.Raycast (backwardPos,dwn, 6)) {
transform.position += Vector3.back;
//did we move to an empty space ?
if (!Physics.Raycast (transform.position,dwn, .5)) {
okToMove=false;
InvokeRepeating("dropDown",1.0,1.0);
}
}
}
insideObject.rotation.eulerAngles.y=180;
}
//move right
if (Input.GetKeyDown(KeyCode.RightArrow)) {
if (Physics.Raycast (transform.position, r, hit,1)) {
print ("There is something in front of the object!");
if(hit.collider.gameObject.tag!="Push"){
transform.position += Vector3.up;
}else{
print ("Push!");
hit.collider.gameObject.transform.position += Vector3.right;
transform.position += Vector3.right;
}
}else{
Debug.Log("nothing in front");
if (Physics.Raycast (rightPos,dwn, 6)) {
transform.position += Vector3.right;
//did we move to an empty space ?
if (!Physics.Raycast (transform.position,dwn, .5)) {
okToMove=false;
InvokeRepeating("dropDown",1.0,1.0);
}
}
}
insideObject.rotation.eulerAngles.y=90;
}
//move left
if (Input.GetKeyDown(KeyCode.LeftArrow)) {
if (Physics.Raycast (transform.position, l, hit,1)) {
print ("There is something in front of the object!");
if(hit.collider.gameObject.tag!="Push"){
transform.position += Vector3.up;
}else{
print ("Push!");
hit.collider.gameObject.transform.position += Vector3.left;
transform.position += Vector3.left;
}
}else{
Debug.Log("nothing in front");
if (Physics.Raycast (leftPos,dwn, 6)) {
transform.position += Vector3.left;
//did we move to an empty space ?
if (!Physics.Raycast (transform.position,dwn, .5)) {
okToMove=false;
InvokeRepeating("dropDown",1.0,1.0);
}
}
}
insideObject.rotation.eulerAngles.y=-90;
}
}
//fall down
if (Physics.Raycast (transform.position,dwn,hit, .5)) {
var t:Timer;
if(hit.collider.gameObject.tag=="HasMission"){
Debug.Log("has mission");
if(!showingMission){
showingMission=true;
t=GameObject.Find("Timer").GetComponent("Timer") as Timer;
t.startTimer();
}
}else if(hit.collider.gameObject.tag=="EndMission"){
}
}
if (Physics.Raycast (transform.position,dwn,hit, .5)) {
var t1:Timer1;
if(hit.collider.gameObject.tag=="HasMission1"){
Debug.Log("has mission");
if(!showingMission2){
showingMission2=true;
t1=GameObject.Find("Timer1").GetComponent("Timer1") as Timer1;
t1.startTimer();
}
}else if(hit.collider.gameObject.tag=="EndMission1"){
}
}
}
function dropDown(){
transform.position += -Vector3.up;
var dwn = transform.TransformDirection (Vector3.down);
if (Physics.Raycast (transform.position,dwn, .5)) {
okToMove=true;
CancelInvoke();
}
}
function isShowingMission(){
return showingMission;
}
function isShowingMission2(){
return showingMission2;
}
Comment