unity 3d character controller
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);
}
}
Also in C#:
- Title
- how to raycast unit
- Category
- C#
- Title
- conditional compilation c#
- Category
- C#
- Title
- unity lerp
- Category
- C#
- Title
- how to insert into a list c#
- Category
- C#
- Title
- check for collision unity c#
- Category
- C#
- Title
- when do i need to end a sentence with ; in c#
- Category
- C#
- Title
- razor preview
- Category
- C#
- Title
- what type of variable is true or false in c#
- Category
- C#
- Title
- c# find element in list of list
- Category
- C#
- Title
- create object in c#
- Category
- C#
- Title
- how to hide a panel ui unity
- Category
- C#
- Title
- html hidden text
- Category
- C#
- Title
- unity transformer double en float
- Category
- C#
- Title
- what function is called just before the a script is ended c#
- Category
- C#
- Title
- c# mathf.ceiling
- Category
- C#
- Title
- c# making a folder wpf
- Category
- C#
- Title
- Assets/Scripts/Snake.cs(187,10): error CS0029: Cannot implicitly convert type `UnityEngine.Vector2Int' to `System.Collections.Generic.List<UnityEngine.Vector2Int>'
- Category
- C#
- Title
- unity create primitive
- Category
- C#
- Title
- unity clamp rotation
- Category
- C#
- Title
- what does thismean incsharp public static void Main
- Category
- C#
- Title
- ignore fakeiteasy
- Category
- C#
- Title
- c# if statement
- Category
- C#
- Title
- c# move with arrow keys
- Category
- C#
- Title
- unity instantiate
- Category
- C#
- Title
- random from list c#
- Category
- C#
- Title
- c# check if string is in array
- Category
- C#
- Title
- replace all ponctuation characters c#
- Category
- C#
- Title
- escape double quotes c#
- Category
- C#
- Title
- copy a list in c# unity
- Category
- C#
- Title
- add row count devepxress report
- Category
- C#
- Title
- c# md5 hash file
- Category
- C#
- Title
- How to solve error in ExecuteNonQuery() in asp.net
- Category
- C#
- Title
- datagridview select row column cell c#
- Category
- C#
- Title
- unity quaternion
- Category
- C#
- Title
- unity on trigger enter
- Category
- C#
- Title
- c# mixed multidimensional array
- Category
- C#
- Title
- c# delegate return value invoke
- Category
- C#
- Title
- c# make http request
- Category
- C#
- Title
- configure 1 to 1 relation ef
- Category
- C#
- Title
- mouseposition unity
- Category
- C#
- Title
- c# code snippet template
- Category
- C#
- Title
- how to disable a gameObject unity c#
- Category
- C#
- Title
- external font family uwp c#
- Category
- C#
- Title
- how to create a variable in C#
- Category
- C#
- Title
- split string in c#
- Category
- C#
- Title
- c# global enumerator
- Category
- C#
- Title
- Length = '((System.Net.RequestStream)RequestStream).Length' threw an exception of type 'System.NotSupportedException'
- Category
- C#
- Title
- how to declare a string c#
- Category
- C#
- Title
- unity custom editor save changes
- Category
- C#
- Title
- unity button interactable
- Category
- C#
- Title
- httpclient soap request c#
- Category
- C#
- Title
- what is the and in c#
- Category
- C#
- Title
- c# getter setter
- Category
- C#
- Title
- print content of array c#
- Category
- C#
- Title
- f string C#
- Category
- C#
- Title
- c# EncoderParameter
- Category
- C#
- Title
- c# bitmap to Image
- Category
- C#
- Title
- c# clone stream
- Category
- C#
- Title
- linq foreach c#
- Category
- C#
- Title
- git set origin
- Category
- C#
- Title
- unity get scrollbar value
- Category
- C#
- Title
- c# dictionary literal initializer
- Category
- C#
- Title
- create char array c#
- Category
- C#
- Title
- c# string code ascii
- Category
- C#
- Title
- how to split a string with strings in c#
- Category
- C#
- Title
- c# change label forecolor code
- Category
- C#
- Title
- landscape print gridcontrol devexpress
- Category
- C#
- Title
- roulette algorithm genetic algorithm
- Category
- C#
- Title
- how to run csharp in visual studio code
- Category
- C#
- Title
- c# interview questions
- Category
- C#
- Title
- No context type was found in the assembly
- Category
- C#
- Title
- c# using get set methods
- Category
- C#
- Title
- how to make pressing enter an event in c#
- Category
- C#
- Title
- c# duplicate object instance
- Category
- C#
- Title
- cannot apply indexing with to an expression of type 'object'
- Category
- C#
- Title
- button commandfield commandargument pass textbox
- Category
- C#
- Title
- debug.log
- Category
- C#
- Title
- check if number is even or odd c#
- Category
- C#
- Title
- c# get object property value by name
- Category
- C#
- Title
- compile in one single exe c#
- Category
- C#
- Title
- unity line renderer position count
- Category
- C#
- Title
- c# sql duplicate key exception
- Category
- C#
- Title
- zip file ignoring directory starting with dot
- Category
- C#
- Title
- c# format string to date yyyymmdd
- Category
- C#
- Title
- wpf binding object get value
- Category
- C#
- Title
- c# silent execute exe
- Category
- C#
- Title
- unity3d quaternion add 90 degrees
- Category
- C#
- Title
- how to trim path in C#
- Category
- C#
- Title
- get enum value c#
- Category
- C#
- Title
- how to get value from object in c#
- Category
- C#
- Title
- microsoft input tool need .net framework
- Category
- C#
- Title
- c# Sleep
- Category
- C#
- Title
- c# rsa example
- Category
- C#
- Title
- c# polymorphism
- Category
- C#
- Title
- initialize matrix c#
- Category
- C#
- Title
- c# check if string is all numbers
- Category
- C#
- Title
- unity 3d mouse look script
- Category
- C#
- Title
- switch case c# range
- Category
- C#
- Title
- string.charat c#
- Category
- C#
- Title
- array c#
- Category
- C#