Unity3D 运动之Move函数和translate

本文介绍了Unity3D中的CharacterController.Move和Transform.Translate两种移动方式。CharacterController.Move用于复杂移动,考虑碰撞但不应用重力;而Transform.Translate则用于简单平移,可以指定相对坐标系进行移动。
摘要由CSDN通过智能技术生成

CharacterController.Move 移动

function Move (motion : Vector3) : CollisionFlags

Description描述

A more complex move function taking absolute movement deltas.

一个更加复杂的运动函数,每次都绝对运动。

Attempts to move the controller by motion, the motion will only be constrained by collisions. It will slide along colliders. CollisionFlags is the summary of collisions that occurred during the Move. This function does not apply any gravity.

尝试着通过动力移动控制器,动力只受限制于碰撞。它将沿着碰撞器滑动。CollisionFlags 是发生于Move的碰撞的概要。这个函数不应用任何重力。

  • This script moves the character controller forward 
    // and sideways based on the arrow keys.
    //这个脚本用箭头键向前移动和侧移角色控制器。
    // It also jumps when pressing space.
    //当按下空格键时,它跳起。
    // Make sure to attach a character controller to the same game object.
    //确保把一个character controller组件附加到同一个游戏物体上。
    //It is recommended that you make only one call to Move or SimpleMove per frame.
    //建议你每帧只调用一次Move或者SimpleMove。 
    
    
    
    
    public class example : MonoBehaviour {
    	public float speed = 6.0F;
    	public float jumpSpeed = 8.0F;
    	public float gravity = 20.0F;
    	private Vector3 moveDirection = Vector3.zero;
    	void Update() {
    		CharacterController controlle
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值