Hi
I want, in game, to allow player to jump only when he is in selected area. I also want various zones. So if player jump while he is passing green zone, he gots better jump then when he do it in blue zone. Is there possible to create something like this in unity ? Also I would like to add zones and setup how big should zones should be.
Thank you for any help
or hint in advance.
1.You can try with triggers:
-
or with positions. Add empty gameobjects in the zones start and end (4 in your case). Then check the players position:
if (transform.position.x > P0.x && <P1.x) {//can jump average}
else if (transform.position.x >= P1.x && < P2.x) {//can jump best}
…
-
or something other from the many possibilities (raycast as example)
1 Like
Thank you for your help. I got some ideas based on your answer. It should be some custom component which let designer define zones. (some kind of array, with lenght of zone in pixels) It will have trigger. And when player jump i do some raycasting, to discover which zone. Only one thing i currently dont know, is how to make zones visualy appear in editor.
Maybe line renderer between the points ? Sorry, Unity has much new funktions and don’t know about them
I am sure there is something simple for visiblity 
Line renderer might be fine
But I used already this functionality
OnDrawGizmos - its executed where all gizmos are drawn. So the code in OnDrawGizmos will execute only in editor. And than I used cubes to draw different jump areas. (I would rather have 2D quad or something like this, but cube was only option avaliable. In 2D cubes looks like quads)
void OnDrawGizmos()
{
if (zones.Length == 0 || zones.Length > colors.Length)
{
return;
}
float xPos = this.transform.position.x;
// Gizmos.DrawCube, kresli zo stredu.
for (int i = 0; i < zones.Length; i++)
{
float zoneSize = widthJumpArea * zones[i]; // vypocitam aka siroka ma byt kocka
xPos += zoneSize / 2; // pripocitam polovicku dlzky kocky, lebo kresli kocku od stredu
Gizmos.color = colors[i];
Gizmos.DrawCube(new Vector3(xPos, this.transform.position.y), new Vector3(zoneSize, heightJumpArea));
xPos += zoneSize/2; // pripocitam druhu polovicku dlzku kocky, abo xPos pointer bol na konci objektu ktory som vykreslil
}
}