Scripts enity3d walk js
Js script s enity 3d for walks
#e03e2d;">using UnityEngine;
#e03e2d;">using System.Collectg System.Collections;
#e03e2d;">// Этот скрипт на движение персонажа через контроллер
#e03e2d;">// and sideways based on the arrow keys.
#e03e2d;">// It also jumps when pressing space.
#e03e2d;">// Make sure to attach a character controller to the same game object.
#e03e2d;">// It is recommended that you make only one call to Move or SimpleMove per frame.
#e03e2d;">public class ExampleClass: MonoBehaviour
#e03e2d;">{
#e03e2d;">CharacterController characterController;
#e03e2d;">public float speed = 7.0f;
#e03e2d;">public float jumpSpeed = 8.0f;
#e03e2d;">public float gravity = 25.0f;
#e03e2d;">private Vector3 moveDirection = Vector3.zero;
#e03e2d;">void Start()
#e03e2d;">{
#e03e2d;">characterController = GetComponent<CharacterController>();
#e03e2d;">}
#e03e2d;">void Update()
#e03e2d;">{
#e03e2d;">if (characterController.isGrounded)
#e03e2d;">{
#e03e2d;">// We are grounded, so recalculate
#e03e2d;">// направление перемещения непосредственно от оси
#e03e2d;">moveDirection = new Vector3(Input.GetAxis(«Horizontal»), 0.0f, Input.GetAxis(«Vertical»));
#e03e2d;">moveDirection *= speed;
#e03e2d;">if (Input.GetButton(«Jump»))
#e03e2d;">{
#e03e2d;">moveDirection.y = jumpSpeed;
#e03e2d;">}
#e03e2d;">}
#e03e2d;">// Активация гравитации. Гравитация умножается на deltaTime дважды (один раз здесь и один раз ниже)
#e03e2d;">// when the moveDirection is multiplied by deltaTime). This is because gravity should be applied
#e03e2d;">// as an acceleration (ms^-2)
#e03e2d;">moveDirection.y -= gravity * Time.deltaTime;
#e03e2d;">// Move the controller
#e03e2d;">characterController.Move(moveDirection * Time.deltaTime);
#e03e2d;">}
#e03e2d;">}
ARTZINE 2 года назад #
С этим кодом, персонаж может ходить