Hello, I’m having an issue with my iphone game where when the player object, (which uses a character controller) walks into a collectable/powerup it causes a very slight lag spike.
However, and here comes the weird part, this only seems to happen the first four times or so, after which the collectables behave very smoothly, I’d like to know why this is happening.
Heres the script I’m using:
#pragma strict
var supplyValue:int = 1;
internal var parentRigidbody: Rigidbody;
internal var parentTransform: Transform;
function Awake ()
{
parentRigidbody = this.transform.parent.rigidbody;
parentTransform = this.transform.parent.transform;
}
function OnSpawned ()
{
parentRigidbody.isKinematic = false;
countdownTillCleanup();
countdownTillPhysicsOff();
parentRigidbody.AddForce(-Vector3.up * 400);
}
function countdownTillCleanup()
{
yield WaitForSeconds(30);
PoolManager.Pools["Consumables"].Despawn(parentTransform);
}
function countdownTillPhysicsOff()
{
yield WaitForSeconds(3);
parentRigidbody.isKinematic = true;
}
function OnTriggerEnter(col : Collider)
{
if (col.tag == "player")
{
col.SendMessageUpwards("IncreaseSupplies", supplyValue, SendMessageOptions.DontRequireReceiver);
PoolManager.Pools["Consumables"].Despawn(parentTransform);
}
}
The script uses poolmanager 4 to instance the collectables, twenty of which are pre spawned at the start of play, so this lag can’t be due to collectables being initiated or destroyed.
It may also be worth noting that the collectable gameobject consists of a mesh render, a rigidbody and a box collider. Then a child gameobject consisting of a much larger trigger box collider and the above script.
The player object meanwhile consists of a character controller, listener, then a bunch of unrelated scripts and numerous child objects none of which have the player tag or colliders of their own.
To clarify the lag spikes only occur on the iphone when the player object collides with a collectable, and only the first four or so times such collisions occur.
I’ve been trying all kinds of things for some time to try and resolve this without any luck and I’m really hoping one of you has encountered something like this before, i’d be very much grateful for any responses though.