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 :: imageLocation in C# 
Csharp :: edit form item from class C# 
Csharp :: Helper Routine GetRect¶ Calculates the area of a scaled down page: 
Csharp :: virtual list entity framework 
Csharp :: c# ile ürün çekme - htmlagilitypack 
Csharp :: .net new template 
Csharp :: How to set a Printer Port in C# on a specified Printer 
Csharp :: how to make a destroy reference in unity 
Csharp :: 1180 - Lowest Number and Position C# 
Csharp :: how to remove something in c# 
Csharp :: select startup item visual studio 2019 
Csharp :: {} is this used for code blocks in c# 
Csharp :: c# user and password verification 
Csharp :: function documentation c# exception 
Csharp :: Unity Hollow Blender Model 
Csharp :: convert console app to linux 
Csharp :: record keyword c# 
Csharp :: cluster size C: powerschell 
Csharp :: best free Modern Design frameworks C# 
Csharp :: c# arithmetic operators 
Csharp :: windowsform mail sender app 
Csharp :: convert string csv line to list long c# 
Csharp :: httprequestmessage with authorization .net 5 
Csharp :: DrawImage resize to target size c# 
Csharp :: textbox center align winform 
Csharp :: recursively fing root of tree 
Csharp :: c# Detect Cycle in a Directed Graph 
Csharp :: osk c# 
Csharp :: PUN 2 Network Transform View Jittery Movement 
Csharp :: id dublication exception c# .net core 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =