zoukankan      html  css  js  c++  java
  • 键盘控制角色移动脚本和摄像机跟随脚本

     1 void Update () {
     2         float h = Input.GetAxis("Horizontal");
     3         float v = Input.GetAxis("Vertical");
     4         Vector3 vel = rigidbody.velocity;
     5         if (Mathf.Abs(h) > 0.05f || Mathf.Abs(v) > 0.05f) {
     6             rigidbody.velocity = new Vector3(-h * velocity, vel.y, -v * velocity);
     7             transform.rotation = Quaternion.LookRotation(new Vector3(-h, 0, -v));
     8         } else {
     9             if (agent.enabled == false) {
    10                 rigidbody.velocity = Vector3.zero;
    11             }
    12         }
    13         if (agent.enabled) {
    14             transform.rotation = Quaternion.LookRotation ( agent.velocity  );
    15         }
    16     }
     1 using UnityEngine;
     2 using System.Collections;
     3 
     4 public class FollowTarget : MonoBehaviour {
     5 
     6     public Vector3 offset;
     7     private Transform player;
     8 
     9     // Use this for initialization
    10     void Start () {
    11         player = GameObject.FindGameObjectWithTag("Player").transform;
    12     }
    13     
    14     // Update is called once per frame
    15     void FixedUpdate () {
    16         Vector3 targetPosition = player.position + offset;
    17         transform.position = Vector3.Lerp(transform.position,targetPosition,Time.deltaTime*8.0f);
    18     }
    19 }
  • 相关阅读:
    04.DRF-开发REST 接口
    03.DRF-设计方法
    02.DRF-认识RESTful
    01.DRF-Web应用模式
    14.Django-xadmin和富文本编辑器
    13.Django-分页
    12.Django-admin
    11.Django-form表单上传文件
    android 基于wifi模块通信开发
    android蓝牙通讯开发(详细)
  • 原文地址:https://www.cnblogs.com/Akishimo/p/5091765.html
Copyright © 2011-2022 走看看