AI spawns in face-down...
Hi, I'm working on a stealth game where the enemy ai patrols a series of waypoints. My issue is that when the game starts, the AI spawns in face-down instead of right-side-up WITHOUT falling over, if that make sense.
The enemy is just a simple cube with a face on it, and for some reason it doesn't spawn in as I have it set up in the "Scene" view (where they are facing the way they are supposed to.)
Please help me out, guys. I really have been having a hard time with this project and the AI is not making it any easier :(
I can supply the enemy scripts if anybody wants/needs them...
$$anonymous$$aybe some script is altering it's transform. Take a look in scripts which have reference to your AI object.
Hmm... I'm using a script I found for an enemy patrol behavior that relies on Nav$$anonymous$$eshAgent to work, and it seems that it is Nav$$anonymous$$eshAgent that causes the problem.
$$anonymous$$aybe my patrol script is fucky? Thanks...
Answer by tanoshimi · Nov 08, 2016 at 11:51 AM
The third parameter to the Instantiate() specifies the initial rotation of the instantiated gameobject. Sounds like you need to rotate that quaternion by 90 degrees counter-clockwise around the x axis.
How would I apply that to my code? I do not call for Instantiate in the code already. Should I just throw an instance of it into my start function?
You said "the AI spawns in". How exactly are you spawning something without Instantiate?
I guess I misspoke. I placed the enemy directly into the game-world, not through using a spawner or spawn script, if that makes sense.
Is that a no-no in gamedev? Should I be using a spawner ins$$anonymous$$d? I'm still new at this, hah.
Answer by Larsthedude · Nov 08, 2016 at 02:07 PM
UPDATE:
It Seems that applying a NavMeshAgent component break the model, causing it to go face-down. Here's the script I'm using on the enemy that accesses the NavMesh...
// Patrol.js
var points: Transform[];
var destPoint: int = 0;
var agent: GameObject;
function Start() {
// Disabling auto-braking allows for continuous movement
// between points (ie, the agent doesn't slow down as it
// approaches a destination point).
GotoNextPoint();
}
function GotoNextPoint() {
// Returns if no points have been set up
if (points.Length == 0)
return;
// Set the agent to go to the currently selected destination.
agent.destination = points[destPoint].position;
// Choose the next point in the array as the destination,
// cycling to the start if necessary.
destPoint = (destPoint + 1) % points.Length;
}
function Update() {
// Choose the next destination point when the agent gets
// close to the current one.
if (agent.remainingDistance < 0.5f)
GotoNextPoint();
}
Any Ideas?~
Your answer
Follow this Question
Related Questions
how could I spwan a prefab and then have it propelled foward as if thrown? 1 Answer
Making an endless hallway with random objects spawning 0 Answers
When enemy spawns it loses the script settings. 0 Answers
Making an object spawned from a list became a child of the player? 0 Answers
Trouble With Creating A Collection of Enemy Prefabs and Spawning Them 0 Answers