12 第1页 | 共2 页下一页
返回列表 发新帖
查看: 5202|回复: 14

第三视角角色移动控制基础教程(二)

[复制链接]

5552

主题

2

听众

8万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
11

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

发表于 2011-12-22 15:24:39 |显示全部楼层
Finishing touches



If you try to play the game now, you will see the character moving around. Fantastic!!
He seems a little stubborn and doesn’t want to turn at all though. We will fix that next.
transform.rotation = Quaternion.LookRotation(moveDirection);

this takes the transform (the main orientation of game object), and rotates it by moveDirection. We already set up moveDirection earlier for the angle we want it to be at.
Success…but wait. If you take your hand away from the controls for a second, he will auto-magically rotate back facing right. Dang!
So close. One more thing to fix that. Wrap this if statement around the last line you put in. It should look like this.
if (targetDirection != Vector3.zero) { transform.rotation = Quaternion.LookRotation(moveDirection); }

What this does is that the game object will only try to rotate if the targetDirection is NOT zero. When you take you hand away from the keyboard for a split second, the input values will show (0,0,0), so it thinks that is the target direction.
It isn’t,but it doesn’t know that. The only time that value will show is when you take your hands off, so the if statement simply ignores input when you take your hands off everything.
One last thing. Add this after the entire Update function at the bottom:
@script RequireComponent(CharacterController)

This will make sure a Character Controller component is attached to the game object that the script is attached to. If you forget to add one and you press play, this line will automatically add a component to the game object and save you from a nasty error.
Hit play and watch your character move and rotate around.
Final Thoughts



If for some reason you scrolled down to get the source without reading anything, here is the project set up files and source.
This is a good first step in understanding how basic character movement is put together. A fully done character is complicated, but understanding these concepts are fundamental to building more advanced setups. This set up might seem weird with how the character moves, but when a camera is added along with a few other elements later, it will all make sense. I will try to continue where this example leaves off and explain more with collisions and actions like jumping in the next post.
由 uke  发表
回复

使用道具 举报

ly    

226

主题

1

听众

2755

积分

中级设计师

Rank: 5Rank: 5

纳金币
2755
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

发表于 2011-12-23 20:34:03 |显示全部楼层
路过顶下吧、、、、
回复

使用道具 举报

5969

主题

1

听众

39万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

发表于 2012-1-19 23:04:14 |显示全部楼层
年年岁岁,岁岁年年,春去春来,转眼间又过了一年,小年到,祝福到,愿你在新的一年事业节节高,生活红火火,拜个早年,提前祝你新年好!
回复

使用道具 举报

   

671

主题

1

听众

3247

积分

中级设计师

Rank: 5Rank: 5

纳金币
324742
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

发表于 2012-1-20 23:18:47 |显示全部楼层
除夕夜,春节倒计时,快乐元素在积聚,欢乐军团急行军,迫不急待的我,与新年阳光一道启程,把一年祝福提前给你,祝你红红火火过虎年。
回复

使用道具 举报

1023

主题

3

听众

359

积分

设计实习生

Rank: 2

纳金币
335582
精华
0

最佳新人

发表于 2012-2-1 23:22:55 |显示全部楼层
发了那么多,我都不知道该用哪个给你回帖了,呵呵
回复

使用道具 举报

462

主题

1

听众

31万

积分

首席设计师

Rank: 8Rank: 8

纳金币
2
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

发表于 2012-3-21 23:24:43 |显示全部楼层
不错哦,顶一下......
回复

使用道具 举报

5969

主题

1

听众

39万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

发表于 2012-6-26 23:25:15 |显示全部楼层
水……生命之源……灌……
回复

使用道具 举报

1023

主题

3

听众

359

积分

设计实习生

Rank: 2

纳金币
335582
精华
0

最佳新人

发表于 2012-7-5 23:25:04 |显示全部楼层
很有心,部分已收录自用,谢谢
回复

使用道具 举报

643

主题

1

听众

9937

积分

高级设计师

Rank: 6Rank: 6

纳金币
9935
精华
1

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

发表于 2012-7-6 15:11:38 |显示全部楼层
好好好好好好好好好好好好好好好
回复

使用道具 举报

643

主题

1

听众

9937

积分

高级设计师

Rank: 6Rank: 6

纳金币
9935
精华
1

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

发表于 2012-7-6 15:11:46 |显示全部楼层
好好好好好好好好好好好好好好好
回复

使用道具 举报

12 第1页 | 共2 页下一页
返回列表 发新帖
您需要登录后才可以回帖 登录 | 立即注册

关闭

站长推荐上一条 /1 下一条

手机版|纳金网 ( 闽ICP备08008928号

GMT+8, 2024-4-18 23:58 , Processed in 0.115658 second(s), 33 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部