help script c#
hey im a beginner in unity, and i tried to make an object with 3rd person view
i managed to make first character movement with asdw or arrow key
i make me happy because it was my first script hat can run perfectly
but, what i really want is to make a movement by pressing only W, and controlling the direction by pointing with mouse. its like skyrim controller.
and this the script im using now using UnityEngine; using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
public float moveSpeed;
public float turnSpeed;
public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
public bool grouded = true;
void Start ()
{
moveSpeed = 3f;
jumpSpeed = 8f;
}
void Update()
{
transform.Translate (moveSpeed * Input.GetAxis ("Horizontal") * Time.deltaTime, 0f, moveSpeed * Input.GetAxis ("Vertical") * Time.deltaTime);
//transform.Rotate (Vector3.up, -turnSpeed * Time.deltaTime);
if (Input.GetButtonDown ("Jump") && grouded == true)
{
transform.Translate (0f, jumpSpeed * Time.deltaTime, 0f);
grouded = false;
grouded = true;
}
}
}
oh and i want to make jump script, but that jump script really strange. please helo
Translate moves an object, it doesn't rotate it. You should be able to find a working script to rotate the character with the mouse easily enough anyway.
Your jump script is currently just going to move the player up by a tiny amount every time the jump key is pressed regardless of whether it is on the ground or not since you are setting 'grouded' to false then true in the same frame so it is never actually being changed.
You may want to have your player detect collisions with the ground to deter$$anonymous$$e when it can jump again. The jump movement might want to be done with a coroutine which would be started on pressing jump. Trying to use Translate
with GetButtonDown
is going to mean it only moves on that one frame in which the jump key was down and nothing else.
Your answer
![](https://koobas.hobune.stream/wayback/20220612074125im_/https://answers.unity.com/themes/thub/images/avi.jpg)