系统更新
人物控制
人物控制方式更改
版本 | 内容 |
---|---|
前传 | 2d人物rpg走格子 |
番外 | 传统wasd控制人物走动,停止按键之后人物同时停止运动。 |
新作 | wasd控制人物方向,采用绝对坐标轴,停止按键之后人物不会停止,会按照面向的方向一直走动,直到碰到block停止。 |
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class charaMove : MonoBehaviour {
public float speed = 4;
public float rotSpeed = 12;
int x;
int z;
Vector3 targetPos;
public Vector3 vet= new Vector3(0,0,0);
Vector3 vetStop= new Vector3(0,0,0);
Vector3 oldVet= new Vector3(0,0,0);
void Update () {
if (Input.GetKey (KeyCode.A))
vet = Vector3.left;
if (Input.GetKey (KeyCode.D))
vet = Vector3.right;
if (Input.GetKey (KeyCode.W))
vet = Vector3.forward;
if (Input.GetKey (KeyCode.S))
vet = Vector3.back;
if (!(vet == vetStop)) {
oldVet = vet;
transform.Translate (oldVet * Time.deltaTime * speed, Space.World);
if (oldVet==Vector3.left||oldVet==Vector3.right) {
targetPos = new Vector3 (transform.position.x, transform.position.y, Mathf.RoundToInt (transform.position.z));
transform.position = Vector3.Lerp (transform.position, targetPos, 0.4f);
}
if (oldVet==Vector3.forward||oldVet==Vector3.back) {
targetPos = new Vector3 (Mathf.RoundToInt (transform.position.x), transform.position.y, transform.position.z);
transform.position = Vector3.Lerp (transform.position, targetPos, 0.4f);
}
vetStop = Vector3.zero;
}
Rotating (oldVet);
}
void Rotating(Vector3 targetDir) {//change rotation by Lerp
if (!(targetDir == Vector3.zero)) {
Quaternion targetRot = Quaternion.LookRotation (targetDir, Vector3.up);
transform.rotation = Quaternion.Lerp (transform.rotation, targetRot, speed * Time.deltaTime * 4);
}
}
void forWard(Vector3 targetFor, Vector3 oldTar){//change forward
if(!(oldTar ==targetFor)){
int x = Mathf.RoundToInt (transform.position.x);
int z = Mathf.RoundToInt (transform.position.z);
Vector3 targetPos = new Vector3 (x, transform.position.y, z);
transform.position =Vector3.Lerp(transform.position,targetPos,0.01f);
}
}
void OnTriggerStay(Collider collider){
if (collider.tag == "Block") {
int x = Mathf.RoundToInt (transform.position.x);
int z = Mathf.RoundToInt (transform.position.z);
Vector3 target = new Vector3 (x,transform.position.y,z);
transform.position = Vector3.Lerp (transform.position, target, 0.4f);
this.vetStop = this.vet;
}
}
}
摄像头控制
更新了摄像头跟踪算法,优化了在高建筑的视角跟踪
在高墙边上摄像头不容易被建筑物遮挡
建筑更新
更新了学院教学楼外设