【发布时间】:2019-06-01 03:05:36
【问题描述】:
我正在使用在线教程制作 pacman 克隆。我刚刚了解了 pacman 的运动,当 Pacman 碰到墙时,他就不能再移动了。这是移动脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class pacman : MonoBehaviour
{
public int speed;
Vector2 dest;
// Start is called before the first frame update
void Start()
{
dest = transform.position;
speed = 5;
}
// Update is called once per frame
void FixedUpdate()
{
Vector2 p = Vector2.MoveTowards(transform.position, dest, speed);
GetComponent<Rigidbody2D>().MovePosition(p);
// Check for Input if not moving
if ((Vector2)transform.position == dest)
{
if (Input.GetKey("w") )
dest = (Vector2)transform.position + Vector2.up;
if (Input.GetKey("d"))
dest = (Vector2)transform.position + Vector2.right;
if (Input.GetKey("s"))
dest = (Vector2)transform.position - Vector2.up;
if (Input.GetKey("a"))
dest = (Vector2)transform.position - Vector2.right;
}
}
}
【问题讨论】:
标签: c# unity3d game-physics physics pacman