Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

movement script c#

using UnityEngine;
using System.Collections;

// This script moves the character controller forward
// and sideways based on the arrow keys.
// It also jumps when pressing space.
// Make sure to attach a character controller to the same game object.
// It is recommended that you make only one call to Move or SimpleMove per frame.

public class ExampleClass : MonoBehaviour
{
    CharacterController characterController;

    public float speed = 6.0f;
    public float jumpSpeed = 8.0f;
    public float gravity = 20.0f;

    private Vector3 moveDirection = Vector3.zero;

    void Start()
    {
        characterController = GetComponent<CharacterController>();
    }

    void Update()
    {
        if (characterController.isGrounded)
        {
            // We are grounded, so recalculate
            // move direction directly from axes

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

            if (Input.GetButton("Jump"))
            {
                moveDirection.y = jumpSpeed;
            }
        }

        // Apply gravity. Gravity is multiplied by deltaTime twice (once here, and once below
        // when the moveDirection is multiplied by deltaTime). This is because gravity should be applied
        // as an acceleration (ms^-2)
        moveDirection.y -= gravity * Time.deltaTime;

        // Move the controller
        characterController.Move(moveDirection * Time.deltaTime);
    }
}
Comment

c# movement script

Look at dani tutorials
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# get date 
Csharp :: unity createassetmenu 
Csharp :: how to clear console in c# 
Csharp :: c# random enum 
Csharp :: how to set a custom size for window in monogame 
Csharp :: how to make something addforce in the direction of something in untiy 
Csharp :: c# windows grab screenshot 
Csharp :: print out a dictionary c# 
Csharp :: c# get all inherited classes of a class 
Csharp :: regex for email c# 
Csharp :: usermanager change password without current password 
Csharp :: C# string format sepperate every thousand 
Csharp :: c# copy to clipboard 
Csharp :: c# or command 
Csharp :: c# list string initialize inline 
Csharp :: switch case c# range 
Csharp :: set text in center wpf 
Csharp :: c# long to int 
Csharp :: c# run c# code from string 
Csharp :: defaultconnection appsettings.json 
Csharp :: remap float c# 
Csharp :: There is already a virtual axis named Horizontal registered. unity 
Csharp :: wpf label text color rgb string 
Csharp :: on collision 2d unity 
Csharp :: c# socket receive 
Csharp :: making beep voice in c# 
Csharp :: Use tuple to swap values c# 
Csharp :: c# check if string is directory 
Csharp :: unity how to rotate something to point to something else 
Csharp :: c# générer un nombre aléatoire 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =