Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

basic movement script unity

public float speed = 5;

void Update() {
    float x = Input.GetAxisRaw("Horizontal");
    float y = Input.GetAxisRaw("Vertical");     
    gameObject.transform.Translate(new Vector3(x,y,0) * speed * Time.deltaTime);
}
Comment

unity 3d movement script

//make sure to add a CharacterController to the thing that you want to move

using UnityEngine;

public class PlayerMovement : MonoBehaviour

{

    CharacterController characterController;

    public float jumpSpeed = 8.0f;

    public float gravity = 20.0f;

    public float speed = 9.0f;

    private Vector3 moveDirection = Vector3.zero;

    private void Start()

    {

        characterController = GetComponent<CharacterController>();

    }

    void Update()

    {

        var horizontal = Input.GetAxis("Horizontal");

        var vertical = Input.GetAxis("Vertical");

        transform.Translate(new Vector3(horizontal, 0, vertical) * (speed * Time.deltaTime));

        if (characterController.isGrounded)

        {

            moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0.0f, Input.GetAxis("Vertical"));

            moveDirection *= speed;

            if (Input.GetButton("Jump"))

            {

                moveDirection.y = jumpSpeed;

            }

        }

        moveDirection.y -= gravity * Time.deltaTime;

        characterController.Move(moveDirection * Time.deltaTime);

    }

}
Comment

PREVIOUS NEXT
Code Example
Csharp :: how to make continuous progress bar 
Csharp :: how to backup terrain in unity 
Csharp :: change color unity back and forth 
Csharp :: How to make a capsule walk in unity 
Csharp :: c# printwindow chrome 
Csharp :: c# project default namespace 
Csharp :: imagetarget found event vuforia c# 
Csharp :: distinct and not null c# 
Csharp :: params keycord as var name c# 
Csharp :: c# array does not contain a definition for cast 
Csharp :: CullingGroup 
Csharp :: access autoload godot 
Csharp :: ilist validation wpf mvvm 
Csharp :: c# razor @html.actionlink( edit bootstrap 
Csharp :: linq cross join 
Csharp :: remove lines from textfile 
Csharp :: c# get count from unknown list 
Csharp :: how to declare two int variables in only one line c# 
Csharp :: windows form button image size 
Csharp :: photon2 what is a stream 
Csharp :: new bitmap pixel format c# 
Csharp :: set main camera unity 
Csharp :: c# windows service .net core 
Csharp :: c# close all threads application exit 
Csharp :: what is c# used for 
Csharp :: c# code process to start any exe application 
Csharp :: embed video to exe file with c# 
Csharp :: c# switch statement 
Html :: enter key vue 
Html :: favicon html link 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =