I am using the Patrol(), MoveTowards(), and PickNextWaypoint() functions from the AI.js script in Lerp 3D FPS tutorial. As I bring the instantiated GameObjects in around the Waypoints from far away, the first two move at normal speed, but the subsequent GameObjects move at double speed.
In the MoveTowards function, the amount of movement is given by
direction = forward * speed * speedModifier;
GetComponent (CharacterController).SimpleMove(direction);
but for all of the GameObjects the speed is the same and the speedModifiers are essentially the same, so essentially the direction is the same. Does anyone know what could cause the later GameObjects to move at twice the speed as the first two GameObjects?
What is really strange is that when I look at the speed of the GameObjects:
var getComp : CharacterController = GetComponent(CharacterController);
var speed = getComp.velocity.magnitude;
the speed is the same for the GameObjects, but some of them are moving twice as fast.
Does anyone know what could cause some GameObjects to move twice as fast in the Game screen compared to other GameObjects even though they have the same speed?
Are all of the GameObjects clones or do they all have the same movement script?
Hi andeeee:
Yes, all of the GOs are clones and they have the same movement script. The GOs come from a prefab = prefabGO and are instantiated as instantGO as (and then added to an array):
var instantGO : GameObject;
for(m = 0; m < 5; m++){
instantGO = (Instantiate(prefabGO, InitialPos, InitialRot));
AllGOs.Add(instantGO);
|
So as you can see, all of the GOs are clones of prefabGO.
Also, yes, the GOs all have the same movement script since that script is attached to the prefabGO that they are instantiated from.
I’ve looked at the instantiated GO instances to see if there are any variables that are different between the instances and don’t see any differences.
One experiment I performed was interesting. For the GOs that were moving twice as fast (speedy GOs), I reduced their speed to one-half of the other GOs (normal GOs), and the speedy GOs are now moving at the same speed as the normal GOs.
The interesting thing is that the speedy GOs still turn around by 180 degrees at a rate that is twice as fast as the normal GOs. So it looks like the speedy GOs are getting updated twice as often as the normal GOs.
Does anyone know what could cause that?
Figured out what the problem was.
Patrol() is called in the GO’s Start(). When I was moving the two GOs onto the screen that were moving twice as fast, I was calling Patrol() a second time for those GOs. I’m guessing this caused MoveTowards to get called twice as often for the speedy GOs making them move twice as fast.