unity movement script 3d

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
4

                                    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
3.6
5
Vasco Palma 105 points

                                    using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class PlayerController : MonoBehaviour
{
    CharacterController characterController;
    public float MovementSpeed =1;
    public float Gravity = 9.8f;
    private float velocity = 0;
 
    private void Start()
    {
        characterController = GetComponent&lt;CharacterController&gt;();
    }
 
    void Update()
    {
        // player movement - forward, backward, left, right
        float horizontal = Input.GetAxis(&quot;Horizontal&quot;) * MovementSpeed;
        float vertical = Input.GetAxis(&quot;Vertical&quot;) * MovementSpeed;
        characterController.Move((Vector3.right * horizontal + Vector3.forward * vertical) * Time.deltaTime);
 
        // Gravity
        if(characterController.isGrounded)
        {
            velocity = 0;
        }
        else
        {
            velocity -= Gravity * Time.deltaTime;
            characterController.Move(new Vector3(0, velocity, 0));
        }
    }
}

3.6 (5 Votes)
0
3
1
Andrew Case 140 points

                                    //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&lt;CharacterController&gt;();
    }

    void Update()
    {
        var horizontal = Input.GetAxis(&quot;Horizontal&quot;);
        var vertical = Input.GetAxis(&quot;Vertical&quot;);

        transform.Translate(new Vector3(horizontal, 0, vertical) * (speed * Time.deltaTime));

        if (characterController.isGrounded)
        {

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

            if (Input.GetButton(&quot;Jump&quot;))
            {
                moveDirection.y = jumpSpeed;
            }
        }
        moveDirection.y -= gravity * Time.deltaTime;
        characterController.Move(moveDirection * Time.deltaTime);
    }
}

3 (1 Votes)
0
0
0
LBushkin 85 points

                                    using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    [SerializeField] private float speed = 5.0f;

    private void Update()
    {
        var horizontal = Input.GetAxis(&quot;Horizontal&quot;);
        var vertical = Input.GetAxis(&quot;Vertical&quot;);
        transform.Translate(new Vector3(horizontal, 0, vertical) * (speed * Time.deltaTime));
    }
}

0
0
4
1
Harish S 115 points

                                    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&lt;CharacterController&gt;();
    }

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

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

            if (Input.GetButton(&quot;Jump&quot;))
            {
                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);
    }
}

4 (1 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
unity simple 3d movement script unity 2d movement new movement script unity unity3d how to make a character move 3d movement script in unity unity 3d movement script 2021 download 3d player movement in unity make a player movement unity how to move character to a position in unity? basic movement script c# script move character unity program player movement unity 3d 3d object movement unity movement code c# play movement unity script c# unity player movement script unity c# 3d movement script how to make a movement script unity unity basic player movement script move character in unity unity character.move unity example movement script unity object movement script basic player movement script for unity basic 3d movement script unity move character script unity 3d player movement unity] c# player movement script 3d how to move character unity c# unity movement script 3D c# unity movement script Movement scripting Unity basic movement unity 3d move a character in unity unity game movement 3d player movement script in Unity c# unity movement scripting movement script csharp unity movement script with movement how to make player movement in unity Unity Movement Script 3D 2021 how to move character using code in unity player movement script in unity move 3d character unity How to make a character move with unity 3d How to make a Unity character move simple movement script unity 3d how to make the character move in unity how to move character up in unity basic movement c# unity best way to move character player movement in unity best movement script for unity 3d unity how to make a character move c# unity move character via code what is the best way to make a player movement script unity c# unity basic movement script simple unity 3d movement script How to make character move unity movement scripts in unity simple 3d movement script unity how to make a character move in unity 3d unity3d script player movement how to make a character move in unity 3d c# move character unity how to add movement script in unity unity 3d player movement script how to move the character unity movement in unity 3d movement script unity c# move character unity 3d movement unity script C# basic movement script movement script unity movement script unity c3 unity script for player movement unity make character move unity movement explained how to move character in unity 3d unity how to make character move unity game dev how to move character how to code a movement script in unity movement script c# unity unity code to make character move unity 3d make character move player movement unity movment code in unity moving c# code for unity player movement unity unity rig character rigidbody movement unity VR unity 2d movement script character controller script unity character controller . move unity 3c movement movement in unity c# unity what is the best method to move character 3d character movement script unity3d player movement script unity character movement 3d how to make character move in unity unity what is character controller move player move script unity unity 3d movement controller unity 3d move player unity scripting basic controls move player C# character controller unity move 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 character controller 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 player move command unity player move command uniti&igrave;y player move command unity&ugrave; make a player move in unity unity script movement character controller script for unity 3d movement controller unity 3d unity move player script unity make a player move 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 move player c# movement code basic character movement unity c# c# code movement 3D how to make player movement unity 3d player model movement unity 3d script controller script unity unity moving character unity character script player controller script unity unity character controller script 3d player controller script unity basic movement unity unity character movement unity3d move player 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# how to hgve my player move in unity unity how to make a basic movement script 3d Unity RTS movement 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 move players in unity 3d movement script player movement script unity 2020 3D character.move unity ho to make a player move in unity movement script download unity player movement script 3d download how to make a simple player movement in unity 3d 2019 unity player movement 3d script mnovement code unity player 3d movement unity unity move character with script unity make animation move character how to make a character move in unity 3d 2020 unity move script 3d unity movement script 3d movement unity code unity movement player control unity script unity 2020 movement script how to write a moving script unity mover script unity unity how to character movement making moveement scripts in unity script movement unity how to move a player model in unity unity player controller script how to make a unity 2020 movement script C# unity player movement chacter movment script unity 3d movement in untiy 3D how to make move script unity UNITY CHARACHTER MOVE movement script unity 3d c# movement script for unity 3d unity basic movement script unity basic 3d player movment scipt unity how to make a character move in unity full movement script for unity unity character controller 3d script player movement unity 3d movement code for c sharp movement unity character movement unity How to make a movement script unity 3D C&pound; How to make a movement script unity 3D player movement c# unity unity player movement how to make move at unity c# unity movement function basic movement script unity how to move character script rcr movement unity unity c# walk script unity move player 3d unity charecter movement script free unity player movement c# unity charecter movement script c# movement unity how to add a move player in unity movement script unity 2019 C# player movement script unity moving character in unity unity movement script. how to make player move in unity unity docs controller move 3d movement unity script unity a* moving c sharp movement script unity c sharp movement script unity movement script c&auml; unity 3d movement script 2020 unity playert mvemebt script c sharp movement player movement code in unity 3d player movement code in unity easy c# move script free unity movement scrips character movement script movement in c sharp Unity [player movement how to make movement in c sharp movment script unity 2019 how to move a player unity movement unity scrip unity 3d simple movement move player charcater uniy unity documentation moving unity 3d move script PlayerMovement script unity 3d character movement unity 3d character movement unity 3f player movement unity script movement controller unity documentation C# script move 3d unity documentation for moving sample move script unity unity player moevemnt script 3d 3d movement script c# unity3d movement unity how to move a player unity player movement 3d script c# character move script unity unity 3d basic movement script movement script unity 3d unity player movement code in c# player movement unity3d unity how to move player example movement unity unity movement commands c# unity walking script 3d function move unity how to move player in unity 3d how to move player in unity Make a character movable in unity unity movement code player movement script for unity unity player movement script 3d reference 3d movement referenc script unity Move method unity player movement controller script unity 3d player movement code unity how to code movement in unity 3d movement coding unity 3d c# unity how to make a player move unity c# movement script c# movement script unity basic character controller unity player movement 3d unity unity simple player movement script how to make a 3d movement script in unity simple player movement script unity how to move a character in unity 3d how to move a character in unity how to move unity script unity 3d player movementscript unity player movementscript how to code movement in c# reposition player in unity movement unity3d script movement unity3d scripts move unity unity 3d player move script unity character controller script 3d 3d character controller unity script unity moving a player 2018 unity movement script move in unity how to move in unity unity 3d player controller script moving player unity move a play in unity unity how to make a character move how to move the character in unity unity 3d player movement script c# playermovement type unity unity script player movement unity c# player movement c# movemenr c# movement' unity character movement 3d scripts free download unity movement sample 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 do i make a player move unity how to move in unity 3d move player script unity 3d character controller script unity how to make a palyer move in unity unity 3d character controller script basic 3d movement unity controller movement in unity simple C# movement script unity on move function unity on m ove how do you make a carather move in unity How to muve in unity 3d moving in unity 3d unity 3d movement code unity script formovement unity script for movement 3d player movment unity how to make a moving character in 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 script for movement in unity how to make it look like player is moving unity 3d movment c# unity unity player movement sdcript c# unity how to move simple character movement unity unity plauer movement script c# movment unity player movement script 3d 2020 c# unity movment Unity player movement script C# c# movement 3d c# 3d movement c# 3d movements c# movement unity documentation c#movement movements control unity unity documentation c# wsad movement unity documentation c# movement unity 3d movment character movement script unity how to move character in unity unity character movement script how does .move work in unity unity script move player move script unity movement script in unity unity move method how to move a palyer in unity unity Move unity simple movement script unity moving in script unity player movement script 3d motion player unity unity player script 3d character movement script unity how to change movement in unity safely move scripts in unity 3d movement script unity simple unity movement script 3d unity movement unity code 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# how to do movement in unity C# unity movement controller movement script 3d unity player script unity movement scipt for character in unity C# unity movement unity player movement code how to make the player move in unity unity writing movement scripts how to make your character move in unity how to make a movement script in unity 3d unity player movement movement in unity 3d how to code a movment c# Basic movement script in unity 3d unity character controller move 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 in unity 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 character movement unity unity 3d character movement script unity 3d character movement 3d player movement script unity player movment script unity basic character movement unity c# player movement script 3d player movement unity unity 3d movescript c# player movement script c# Unity movement script 3D unity move command movement 3d unity simple movement script unity Move() unity unity 3d movement script c# how to move character in script unity unity move player move player unity how to make player move in unity 3d movement script unity unity move character 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

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
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