- Home /
How to instantiate gameObjects based on huge paleyr speed?
Hello. Need some help.
I'making simple runner game and right now trying to add pick up THAT SPEED UP player. To my player I've atached CREATOR game object that moves forward with the player and randomly creates obstacles and pick ups. But when veloscity of my player is not so big, it is working good and when I aplly some additional speed my creator cant handle to Instantiate new game objects. The idea of creator that he instantiate gameObjects based on CREATOR's transform position. And when player moves realy fast it skips some prefab instantiation because position changing realy fast. Any idea ho to handle it? Is it good idea to create prefab of prefabs, for creator can handle it?
In player controller I use this:
private void Update()
{
if (moveLeft)
{
playerRb.velocity = new Vector3(-sideForce, -0.5f, speed);
}
else if (!moveLeft)
{
playerRb.velocity = new Vector3(sideForce, -0.5f, speed);
}
}
In creator contoller I use this:
private void Update()
{
if ((int)transform.position.z % distanceToInst == distanceToInst - 1 && needToCreate)
{
Instantiate(objToInst, new Vector3(transform.position.x, transform.position.y, (int)transform.position.z), Quaternion.identity);
}
}
But when my PLAYER SPEED is to big, my creator cant handle to INSTANTIATE object each time when transform.position.z % distanceToInst == distanceToInst. I use from 10 to 20 distanceToInst. transform.position.z is based on PLAYER TRANSFORM.
Your answer
Follow this Question
Related Questions
When cloning, how do you make your clones keep the original properties? 2 Answers
Instantiate objects faster and faster over game time,Instantiate objects faster and faster over time 1 Answer
Gun Projectile Shooting In Wrong Direction (Javascript) 1 Answer
Rotation and Velocity of bullets. 1 Answer
raycast and instantiat advice 0 Answers