Hi guys, i have a question, a player will be there and a whole model of terrain will be there like temple run, but here the terrain is limited . I want the terrain to move and player to just keep animating, when the user presses right or left the terrain will turn and continue running, can anyone help me ?
Seems pretty simple. You simply manipulate the terrain’s matrix based on player’s key presses.
What makes you think the terrain moves? It’s the player that moves through the terrain.
The player runs at a constant speed, and the camera stays at fixed position behind him.
The terrain is tiled, so it never runs out.
i’v managed to create that , everything works amazing , but i still want a script that moves him with a static speed at first then get faster at a specific time , i tried with addforce , but it keeps adding and it will be so fast , i need a lil help on that .
Is there any specific reason you want to do it like that? There’s usually only a few situations where you need to make it complicated like that.
and kinda lows the FPS , generating a terrian and moves the player is better ,
It works out better to move the terrain and keep the player at the origin because of the issues with float accuracy as numbers increase. The further you get from the origin, the less accuracy, so things start being placed oddly.
Edit: Little Angel’s post below has an even better way.
You’re saying that the player’s position stored as a floating-point number has limited range.
If he keeps running, his position will eventually get so large it will overflow.
I see no reason why someone couldn’t tile the player’s position to make it relative
to the active terrain tile/block, so the position doesn’t overflow. It just wraps around to zero again.
Or another way to describe it, the player is “transported” to the start of the new terrain block.
So, the terrain never moves.
I highly doubt you will have many float problems. Especially if you work in a small scale.
The main problem with moving the world is dealing with the static collider cache.
Unity will cache the information on all static colliders in the scene. Static colliders are defined as a collider without a rigidbody. Every time you move a static collider, Unity will recache all of the static colliders in the scene. This is why it’s important to use a kinematic rigidbody collider on objects that move. Let’s say you have a collecting game with 100 rotating coins. If these are simple colliders, without a rigidbody, you will be recaching your static colliders 100 times per frame. Making them kinematic rigidbody colliders means you can continue to manipulate them using their transform, and you won’t recache your static geometry.
If you move the scene, with all of it’s static colliders, you will need to recache your entire scene every frame, or you will need to make sure all geometry on your level used kinematic rigidbody colliders.
This is the reason many people choose to tile or portal moving characters rather then move the world.
This way, the world is static, the character is running, and periodically, the character is reset to be close to origin.