|
I'm working on a 2D sidescroller where my Z axis is always "0". I'm importing FBX Models from Cheetah 3d with animations attached. I have the animations set to loop when the enemy is moving back and forth between waypoints. It's a simple waypoint system where the enemy travels to one waypoint then turns to face the second waypoint and travels to it (constant loop). Just a ping pong waypoint system (simple patrol for an enemy). The problem is that the character never faces the right direction when moving from waypoint to waypoint. For instance... one enemy is about 45 degrees off of facing straight ahead... and when he hits his waypoint and turns around he's 45 degrees off of facing straight heading in the other direction. Another enemy is completely faced backwards. He literally moves backwards from waypoint to waypoint. I am not sure if it's my import settings that are screwing this up or if I should be doing something in a script that I'm not. Here is the latest script that I'm working with... wrote several different scripts, tried tons of tutorials, and other scripts and no luck still... same thing over and over... anyhow here's what I got... if anyone has any suggestions or solutions in JS or C# I'd appreciate it (p.s. it makes no difference if I reference global or local positions): var speed : float = 5; var loop : boolean = true; var player : Transform; var searchPlayer : boolean = false; var viewDist : float = 10; var maxPathDist : float = 40; function Awake(){ pathpoint[0] = transform; } function Update(){ if(currentPathPoint < pathpoint.length){ var target : Vector3 = pathpoint[currentPathPoint].localPosition; var moveDirection : Vector3 = target - transform.localPosition; var velocity = rigidbody.velocity; var playerDist : Vector3 = player.localPosition - transform.localPosition; if(moveDirection.magnitude < 1){ currentPathPoint++; } else if(searchPlayer == true){ if(playerDist.magnitude < viewDist){ velocity = Vector3.zero; target = player.localPosition; velocity = (player.localPosition - transform.localPosition).normalized * speed;} if((player.localPosition - pathpoint[currentPathPoint].localPosition).magnitude > maxPathDist){ target = pathpoint[currentPathPoint].localPosition; velocity = moveDirection.normalized * speed; } } else{ velocity = moveDirection.normalized * speed; } } else{ if(loop){ currentPathPoint = 0; } else{ velocity = Vector3.zero; } } rigidbody.velocity = velocity; transform.LookAt(target);}`
(comments are locked)
|
|
is the enemy facing on the blue line?? Ah I see what you are saying... the front of my enemy needs to face forward in the "Z" direction (blue line)... I looked at my enemies and sure enough this is the issue... do you know the way to fix this? And why would my characters not line up correct in the first place?
Apr 01 '12 at 02:27 AM
stingman
Got it working... if anyone has this issue there appears to be a few ways to fix it... but I went back into Cheetah 3d and repositioned my object so it lined up straight with the Z axis.
Apr 01 '12 at 03:40 AM
stingman
This is an extremely common question, has been answered over and over, but I don't think "facing backwards" or "facing wrong way" is a keyword, so difficult to search. Most common answer given is to child the wrong-facing object, adjust the facing, and have the parent do the aiming. "Best" answer is to fix it in the modelling program (but some plp aren't able to do that.)
Apr 01 '12 at 02:36 PM
Owen Reynolds
(comments are locked)
|
