Camera Navigation Problem with GUI.Button

Hi to all,

I am developing a game and I am moving my Main Camera using GUI buttons(GUI.Button()) on the iPhone screen. Whenever I press the button and release it, the camera starts moving and do not stops.
I am using rigidbody.AddForce for moving my camera.

I wish my camera to move when the button is in pressed down state, and when I release the button then I wish my camera to stop instantly.

thanks in advance

unityboy

If you are using a rigidbody without gravity, drag, etc, then adding a force will make an object fly off and never stop. You can make a rigidbody stop sharply by setting its velocity to zero - you could do this when the button is released. However, you might find that the physics engine is not the best way to handle this task. You could also try using transform.Translate to move the camera only when the button is pressed down.

I wish to know which button allow us to execute a code when the button is pressed down…

sorry for replying late. I was away.

and thanks for your reply

unityboy

You could use something like:-

if (GUI.Button(buttonRect, "Move Camera")) {
    transform.Translate(moveVector * Time.deltaTime);
}

It did not worked when my GUI button is in pressed down state. when we release then it works.

Any idea ??

thanks

unityboy

For continuous movement, you should use a RepeatButton rather than an ordinary button.

thanks for the reply…

this is the same as i wanted…

thanks again

unityboy

Any idea to make it “NOT PASS” through the colliders. Transform.translate makes my object pass through wall colliders.

A CharacterController is probably what you’re looking for.

alternatively, use rigidbody and use the velocity / move / addimpulse etc functions on the rigidbody instead of messing with the transform

Yeah, I had initially added the Character Controller. But felt it was too heavy for what I wanted to implement - Just 4 buttons to move/rotate the camera. I had no use for the keyboard or mouse(I just needed it for the buttons).

That is exactly what I tried implementing, until it became kinda complex because I was working with a Character Controller and wrote a separate code for camera with translate and then kinda messed up both. It seemed easy, but after looking through the lines, I lost track of where I was.

I have decided to start afresh tomorrow. This is what I intend to do, add a Character Control and use the CharacterController.Move() or CharacterController.SimpleMove() for the movement and use transform.rotate() for rotating the cameras.