- Home /
fps move forward on GUI Button Press
Hello, I am currently making a First Person Exploration game. I am trying to get my movement working. Exploring will be similar to old school FPS (think wolfenstein 3d and original doom with no looking up or down) I want to create up, down, left, and right buttons on the GUI. Then have the player move up or down on click or rotate left or right ninety degrees with the left and right buttons. Any ideas? Thanks in advance.
its for webplayer, don't ask me, that is the way the client wants it
Answer by jahroy · Nov 16, 2011 at 03:35 AM
I would start by looking at the scripts that come in the Standard Assets folder.
In the subfolder named Scripts there are a bunch of scripts that deal with camera movement and user input.
Here is some documentation for handling user input:
http://unity3d.com/support/documentation/ScriptReference/Input.html
I would also check out the Unity Wiki, which has tons of sample scripts that deal with this.
Here's an entire page full of camera control scripts:
http://www.unifycommunity.com/wiki/index.php?title=Scripts/Controllers
Here's an entire page full of GUI scripts:
http://www.unifycommunity.com/wiki/index.php?title=Scripts/Controllers
I would also recommend searching this site for questions similar to yours.
Here are a couple I found by searching for camera movement:
http://answers.unity3d.com/questions/26263/camera-scripting-references.html
http://answers.unity3d.com/questions/54693/camera-movement-script.html
Answer by Diegosl1207 · Jan 31, 2017 at 08:46 AM
I make a example in a first control person in unity 5 (maybe helps you):
Add default prefab of first control person;
Desable firstPersonalControl script default;
Add this script below;
In a rigidbody: freeze position Y and freeze rotation X, Y and Z.
Sorry for the english...
using UnityEngine; using System.Collections;
public class walkOnFaceDirection : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
var x = Input.GetAxis("Horizontal") * Time.deltaTime * 150.0f;
var z = Input.GetAxis("Vertical") * Time.deltaTime * 3.0f;
transform.Rotate(0, x, 0);
transform.Translate(0, 0, z);
}
}
Your answer
Follow this Question
Related Questions
UI Button should stay highlighted on click 2 Answers
Working between different scenes! 1 Answer
Problem with a button 2 Answers
Unity UI Button not working 1 Answer