Arrow controls (522301)

Hi guys,

I’m making a game for iPhone/iPad. It’s a maze in kinda first person. I want the user to be able to walk around by clicking on arrows. When it’s possible to go left and right, I want both the left and right arrows able to click on. But when there’s only a possibility to go right, the only arrow which can be clicked will be the right one.

I made an example of what I want, because I don’t know if you could understand my explanation :stuck_out_tongue:


So, here it’s only possible to go forward, because on the left and right are walls. The left and right arrow are disabled.


Here it’s possible to go to the left, right and forward. The user can click on every arrow.

I hope you understand what I want, and I hope it is possible. If not, other options are very welcome then!

Denise

Hey Denise.

You forgot to ask a question :face_with_spiral_eyes:

I am going to assume you want some advice on how to do this. It should be quite simple.

Raycast is your friend for this task

Something like this:

            float distanceToTest = 10;// How far from the wall will they be? Lets assume 10.
            if( !Physics.Raycast( transform.position, transform.right, distanceToTest ) ) 
            {
                // We can go right
            }


            if( !Physics.Raycast( transform.position, -transform.right, distanceToTest ) ) // How far from the wall will they be? Lets assume 10.
            {
                // We can go left
            }


            if( !Physics.Raycast( transform.position, transform.forward, distanceToTest ) ) // How far from the wall will they be? Lets assume 10.
            {
                // We can go forward
            }

The question indeed was how to make such a thing, sorry for not asking the question :P.

I tried that code, need I to put it in a JS or C#? I tried both, but didn’t work. It constantly gives me an error about the " ; "
It says: UCE0001: ‘;’ expected. Insert a semicolon on the end.

But that’s already there on that line. So I don’t get it.

And where do I add the script to, to all the walls, to the Person Controller?

I’m really sorry, you say it’s easy but I just don’t understand it :(…

I’m feeling extra helpful :smile:

Here is an example scene with a script to do it for you. It assumes your buttons are each a GameObject.

1443700–77677–$Example.unitypackage (6.28 KB)

Wow, thank you so much! That’s exactly what I wanted!
Hopefully I can get it to move to the left/forward/right by myself, I’m new to all this stuff, so it’s still difficult for me :).

Well, I tried really really hard, have been trying for hours, really, but I don’t get it to work when clicking on the text.
I did made something with the help of Google, and it’s kinda doing what I want, though it’s only for the right arrow.
But when I add this code to the Right arrow object, only the right arrow moves (but that’s kinda logic).
When I add it to the Capsule, the capsule moves as I want it when clicking on it.
But how do I say the Capsule has to move when I click the Right arrow object? (I hope you understand what I’m saying.)

Probably I’m doing things too difficult, cause I don’t understand much of it. If this wasn’t for a school project, I wouldn’t be doing this, haha :p.

This is the code I was talking about. It’s a JS. I tried adding things to your C# document, which I ought to do I guess, but I’m failing hard at understanding it.

var speed = 5;
var target : GameObject;
var test= false;
var number = 1;
var clicked=false;
var moveForward;
var turnRight;
var rotationAmount = 90.0;
 
function OnMouseDown() {
 move();
 }
 
function move()
{
	turnRight = true;
	yield;
	turnRight = false;
	moveForward = true;
	yield;
	moveForward = false;
}
 
function Update()
{
     if(moveForward)
     {
         transform.Translate(0, 0, 5);
     }
 
     if (turnRight)
     {
    transform.Rotate (0, 45, 0);
     }
}

You need to move your target. Target.transform.

uhh, OK, and where do I put that :face_with_spiral_eyes:?

At the moment you apply the transformation to the arrow because you use transform.translate. you want to apply it to the target by using target.transform.translate. it sounds like this is only going to get harder for you. I suggest you take an hour and go through some of the unity tutorials .

if(moveForward)
{
	target.transform.Translate(0, 0, 5);
}

Yes! It worked.
Thank you so very much!!

I put the target.transform.Translate target.transform.Rotate into the moveRight, and now it moves and rotates :)!

It’s true I should go through some tutorials, I’ve watched a few, but not all of them.

But thank you so much for all of your help!