I am working on an RTS game with a top-down orthographic camera.
I have the click to move functionality working except for 1 hiccup. I cannot get the character to stay on a height level of 1 only.
Basically I have the character trapped inside a crater and I want him to have to stay in the crater. However when I click to move anywhere he always moves UP the terrain (even if I try clamping the Y value to 1). I haven't added colliders to the terrain yet so I don't care if hes walking through the crater walls at the moment --- I just don't want him walking UP them.
The logs show that even when the Y value is "clamped" to 1, the character still moves in an upward direction along any terrain height. What am I missing to keep this character grounded on a height of 1 max?
Here is the code:
P.S. I am very new to unity so as simple an answer as possible is much appreciated :)
try moving the "transform.LookAt(hit.point);" line to below where you set groundedHitPoint:
that may work, it would fit the simple criteria
to be sure, you could go a little further.. Instead of the line:
you don't need to pass "canMove" into the collision function.
the var "canMove" is part of the same script, so it's already accessible.Next:
this line is unnecessary; OnCollisionEnter is automatically entered every time the collider attached to the object hits another collider.