- Home /
Creating a road with horizon.
I am making a game in Android. Its a infinite runner. I wanted some help on the plane looking curved while loading new scenes. Like on turns in Subway Surfers.... I am scripting in C#. Thanks guys!
You need to create a random generator, that is placing GameObjects (Array) at a random Position.
I've not reached up to that point... I wanna bend the horizon.... For roads and such stuff... Clouds and fog are good ideas but I need to get further information on the avatar animation and its integration with the environment. Does the plane move or the character? I'm like intermediate with unity... The running part is most confusing...
You could do either. Its easier to have the character move, and as @Lost_C4 said, randomly create GameObjects in front.
But how do I bend the road?? In my case the plane? (Road)
That depends on how your code is implementing the movement. Generally, you are moving the character in the environment and not the environment around the character. Though both techniques are possible, moving one object (the character) is less work than moving an entire environment.
I'm not sure what you mean by "bend the horizon". In the 3D environment, if you want a road to curve or slope, you have to build a that curve or slope into the models you are using.
Answer by Warville · Oct 15, 2013 at 10:39 PM
he wasn't asking for for that guys he wanted the road to bend in X and Y axis ,
the easier way to do that without need to modeling bended models is curve shader , i'm using it now, it's easy all you need to do is to control the X and Y offset value with yur code give it random number from -x to x when x = 0 then the road is straight, but i have only found a basic code that doesn't support lights and shadows if you find out how to add shdow and light to the shader please tell me ,
Shader "Custom/Curved" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_QOffset ("Offset", Vector) = (0,0,0,0)
_Dist ("Distance", Float) = 100.0
}
SubShader {
Tags { "RenderType"="Opaque" }
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
float4 _QOffset;
float _Dist;
struct v2f {
float4 pos : SV_POSITION;
float4 uv : TEXCOORD0;
};
v2f vert (appdata_base v)
{
v2f o;
float4 vPos = mul (UNITY_MATRIX_MV, v.vertex);
float zOff = vPos.z/_Dist;
vPos += _QOffset*zOff*zOff;
o.pos = mul (UNITY_MATRIX_P, vPos);
o.uv = mul( UNITY_MATRIX_TEXTURE0, v.texcoord );
return o;
}
half4 frag (v2f i) : COLOR
{
half4 col = tex2D(_MainTex, i.uv.xy);
return col;
}
ENDCG
}
}
FallBack "Diffuse"
}
Seems good but can you show example code to control it? I'm new to shaders...
I'm guessing that I have to apply it to the road material... I'm I right?
Answer by Sajidfarooq · Aug 28, 2013 at 05:30 PM
Your ground should be created in "pieces", or tiles, as prefabs. Each one is a plane of the same size. The only difference will be the texture on top. You will have straight textures, and bent textures on some. When you need the road to bend, you instantiate the tile which has a bent texture on int.
This is what I am referring to:
Awesome man... Hope this works for for me.... Will let you know....
I'm getting The idea... $$anonymous$$y road will be some sort of a digital highway... So I will have to make the prefabs by myself right?? I'll try it out this weekend... If it works +1 for you my friend!! Gotta sleep now its like 12A$$anonymous$$ here lol.... Thanks....
@boggartfly: If this worked for you, don't forget to mark this question as answered.
Doesn't work. Damn sure tried all variations. Plus I can't control it dynamically.
Your answer
![](https://koobas.hobune.stream/wayback/20220613113120im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Animation play in unity 5??? c# 2 Answers
Play anaimation when key pressed 1 Answer
Add two radius on the same shader 1 Answer