zoukankan      html  css  js  c++  java
  • [Unity菜鸟] Character控制移动

    1. 给角色加角色控制器组件,然后用以下代码可以控制角色移动和跳跃

        float  speed  = 6.0f;
        float jumpSpeed  = 8.0f;
        float gravity  = 20.0f;
    
        private Vector3 moveDirection = Vector3.zero;
    
        void Start()
        {
           // gameObject.rigidbody = false;
        }
        void Update()
        {
            CharacterController controller = GetComponent<CharacterController>();
    
            if(controller.isGrounded)
            {
    	        moveDirection =new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); //Allows for player input
    	        moveDirection = transform.TransformDirection(moveDirection); //How to move
    	        moveDirection *= speed; //How fast to move
    	
    	        if(Input.GetButton("Jump"))
    	        {
    		        moveDirection.y = jumpSpeed;
    	        }
            }
            //Apply gravity
            moveDirection.y -= gravity * Time.deltaTime;
    
            //Move the controller
            controller.Move(moveDirection * Time.deltaTime);	
    	
        }
    

    2. 添加角色控制器后人物下陷问题

  • 相关阅读:
    Json Web Token
    logstash 收集 IIS 日志实践
    Lucene Query In Kibana
    autofac 在.net core 与经典asp.net中的差异
    .net core 集成 autofac.
    向量化
    神经网络学习1
    漏斗限流
    正则化(Regularization)
    简单限流
  • 原文地址:https://www.cnblogs.com/code1992/p/3816741.html
Copyright © 2011-2022 走看看