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# declaration definition 
Csharp :: do loop c# 
Csharp :: can lightning strike the same place twice 
Csharp :: Nullable Types unity 
Csharp :: how to scale text from center in unity 
Csharp :: rb.addforce 3d c# 
Csharp :: c# MD5.Create returning nul 
Csharp :: _swapbatch.foreach multiple statements c# 
Csharp :: syoutube 
Csharp :: generate random string 
Html :: html meta refresh 
Html :: ion-item remove bottom line 
Html :: how open link in new tab 
Html :: bootstrap cdn link 
Html :: display html jupyter 
Html :: meta no cache 
Html :: how to tab in html 
Html :: target _blank 
Html :: bootstrap two buttons side by side with space 
Html :: bootstrap 4 image fit to div 
Html :: html favicon.ico 
Html :: how to add a logo icon in HTML 
Html :: how to add a description to a table html 
Html :: fullpage cdn 
Html :: image src on error 
Html :: svg line 
Html :: bootstrap column vertical align 
Html :: ngfor with index 
Html :: video tag thumbnail 
Html :: html add image from remote source 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =