c# movement script

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);
    }
}

0
0
Awgiedawgie 104555 points

                                    private float speed = 2.0f;
public GameObject character;

void Update () {

	if (Input.GetKey(KeyCode.RightArrow)){
		transform.position += Vector3.right * speed * Time.deltaTime;
	}
	if (Input.GetKey(KeyCode.LeftArrow)){
		transform.position += Vector3.left * speed * Time.deltaTime;
	}
	if (Input.GetKey(KeyCode.UpArrow)){
		transform.position += Vector3.up*speed* Time.deltaTime;
	}forward;
	if (Input.GetKey(KeyCode.DownArrow)){
		transform.position += Vector3.down *speed * Time.deltaTime;
	}
}

0
0
0
0
Krish 24070 points

                                    Look at dani tutorials

0
0
Are there any code examples left?
Create a Free Account
Level up your programming skills with IQCode
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
unity 2d movement basic movement script c# movement code c# c# unity movement script top down movement script C# c# unity movement scripting movement script csharp unity movement c# c# movement unity basic movement c# movement in unity C# basic movement script movement script c# unity player movement unity movment code in unity moving c# code for unity movement in unity c# 3d character movement script unity3d player movement script unity character movement 3d player move script unity unity scripting basic controls move player C# how to code the best movement in c# simple movement c# unity unity free movement script player movement 3d movement unity3d code movement unity 3d code moving script unity basic player movement script unity simple player movement unity3d walk script unity plug in script character movement unity using plug in script character movement unity unity walk script 3d unity walk script unity script movement unity move player script c++ 3D movement script move a player with code unity c# how to make a movement script in unity 3d form.move unity c# movement script 3d how to script player movement in unity unity basic 3d movement code for player c# unity unity simple movement script 3d download c# movement code basic character movement unity c# c# code movement 3D c# code movement player model movement unity 3d script controller script unity unity character script player controller script unity unity character controller script 3d player controller script unity unity character movement how to make player movement in unity 3d 3d movement script unity capsule unity movement script c# moving in unity player script unity c# character controller C Sharp Unity characther controller c# unity unity how to make a momvent script player movement code c# unity how to make a basic movement script 3d custom script move in unity unity player scripts unity c# movement code simple player movement unity c# unity movement code 3d pre made movement scpript unity unity c# 3d movement 3d movement script character.move unity movement script download unity player movement script 3d download unity player movement 3d script mnovement code unity player 3d movement unity unity move character with script unity move script 3d unity movement script 3d movement unity code player control unity script how to write a moving script unity mover script unity making moveement scripts in unity script movement unity unity player controller script C# unity player movement chacter movment script unity 3d movement in untiy 3D how to make move script unity movement script unity 3d c# movement script for unity 3d unity basic movement script basic 3d player movment scipt unity full movement script for unity unity character controller 3d script player movement unity 3d movement code for c sharp character movement unity How to make a movement script unity 3D player movement c# unity unity player movement unity movement function basic movement script C# character movement unity c# walk script unity c# simple movement script unity player movement c# unity charecter movement script c sharp movement script unity c sharp movement script unity movement script c&auml; c sharp movement player movement code in unity 3d easy c# move script character movement script movement in c sharp how to make movement in c sharp C# script move 3d sample move script unity movement script unity 3d unity player movement code in c# c# unity walking script 3d unity movement code unity player movement script 3d reference how to code movement in unity 3d movement coding unity 3d c# unity c# movement script c# movement script unity player movement 3d unity simple player movement script unity how to move unity script unity 3d player movementscript unity player movementscript reposition player in unity movement unity3d scripts move unity unity 3d player move script unity character controller script 3d 3d character controller unity script 2018 unity movement script unity 3d player controller script unity 3d player movement script c# unity c# player movement c# movemenr c# movement' unity character movement 3d scripts free download Character movement code for c# unity script moving unity character move script C# code for character movement unity 3d movemnet player c# unity unity move unity moveinput scrupt how to move in unity 3d move player script unity 3d character controller script unity unity 3d character controller script basic 3d movement unity simple C# movement script how do you make a carather move in unity How to muve in unity 3d unity 3d movement code unity script formovement unity script for movement 3d player movment unity script unity 3d movement code to move in unity unity player movement script c# 3d c# simple movement unity character code unity movement script pc controller movement script unity 3D unity (!moving) unity simple move script 3d player movement c# script unity player movement movement code unity 3d C# movemoent script movement code unity download movement code unity unity player movement sdcript unity plauer movement script c# movment unity player movement script 3d 2020 Unity player movement script C# c# movement 3d c# 3d movement c# 3d movements c# movement unity documentation c#movement unity documentation c# movement unity 3d movment character movement script unity unity character movement script how does .move work in unity unity script move player move script unity unity Move unity simple movement script unity moving in script unity player movement script 3d unity player script 3d character movement script unity safely move scripts in unity 3d movement script unity simple unity movement script 3d unity movement how to make a basic move and looking script in unity 3d input control movement script unity 3d player movement unity 3d motion script c# unity player movement script unity c# movement script 3d unity player script unity movement scipt for character in unity C# unity movement unity player movement code unity writing movement scripts how to make a movement script in unity 3d unity player movement how to code a movment c# Basic movement script in unity 3d full movement script for unity 3d basic movement script unity 3d Player movement c# script unity basic player movement 3d character move script for unity unity 3d player movemnt controller sciprt unity 2019 simple player movement script 3d how to make a player movement script in unity how to make a movement script in C# 3d movement in unity full movement in unity 3d player movement script unity player movment script unity c# player movement script 3d player movement unity unity 3d movescript c# player movement script c# Unity movement script 3D movement 3d unity simple movement script unity Move() unity unity 3d movement script c# how to move character in script unity how to make player move in unity 3d movement script unity unity player movement script movement c# c# script movement C# movement script 3d playermovement unity unity C# movement C# how to move player unity player movement 3d movement in c# simple 3d movement script 3d movement unity unity 3d player movement basic unity movement script unity&igrave; movement 3d script unity&igrave; movement script movement unity 3d basic movement script unity movement script unity movement 3d unity c# player movement script 3d unity c# player movement script unity 3d movement c# walking script c# moving character unity c# moving caracter unity3d player movement unity movement 3d script unity movement script unity 3d movement script player movement script unity how to move in unity c# unity default movement script walking script unity motion script unity player movement unity 3d script player movement script unity 3d script movement unity 3d movement script c#
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Pleased to see you again

Sign up to unlock all of IQCode features:
  • Master useful skills
  • Improve learning outcomes
  • Share your knowledge
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Master useful skills
  • Improve learning outcomes
  • Share your knowledge
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source