12 第1页 | 共2 页下一页
返回列表 发新帖
查看: 4650|回复: 12
打印 上一主题 下一主题

绳子效果实现代码

[复制链接]

1023

主题

3

听众

359

积分

设计实习生

Rank: 2

纳金币
335582
精华
0

最佳新人

跳转到指定楼层
楼主
发表于 2011-8-12 10:42:55 |只看该作者 |倒序浏览
采取的一种变通的办法来实现绳子效果,和官方有一个演示中用到的应该是类似的方法。下面是详细的介绍
The rope is made using character joints, except for the top (which has its mesh unrendered) which uses a hinge joint. All the segments are triggers, rigidbodies using gravity and have a "ladder" tag on each segment except for the top and bottom (The reason for this is shown in the video as to what happens when the bottom segment is tagged ladder). The player climbs the rope by pressing the W or S key.

Everything is done in the player's script. What we don't know is if the problem is in the player, the way the rope is made or both. An alternative method to making the rope or rope climb/swing script is also welcome.

The player does not use a character controller. Below is a snippet of the code. All the climbing
variable does is keep the player from moving left and right as if they were on the ground.

function OnTriggerStay ( other : Collider)
{
if (other.gameObject.tag == "ladder")
{
if (Input.GetKey("w"))
{
rigidbody.velocity.y=0;
rigidbody.velocity.x=0;
rigidbody.useGravity=false;
transform.Translate ( Vector2(0, ClimbSpeed * Time.deltaTime));
DoubleJump = JumpReset;
Climbing = true;
transform.parent=other.transform;
}
if (Input.GetKey("s"))
{
rigidbody.velocity.y=0;
rigidbody.velocity.x=0;
rigidbody.useGravity=false;
transform.Translate (Vector2(0, -ClimbSpeed * Time.deltaTime));
DoubleJump = JumpReset;
Climbing = true;
transform.parent=other.transform;
}
if (transform.parent.tag == "ladder")
{
transform.localPosition.x = 0;
transform.rotation = transform.parent.rotation;
transform.parent.gameObject.rigidbody.AddRelativeForce(Vector3.right * Input.GetAxis("Horizontal") * 1, ForceMode.VelocityChange);
if(Input.GetAxis("Horizontal"))
{
rigidbody.velocity.x=0;
transform.localPosition.x=0;
}
}
}
if (other.gameObject.tag == "Mesh")
{
if (Input.GetKey("w"))
{
//rigidbody.isKinematic = true;
rigidbody.velocity.y=0;
rigidbody.velocity.x=0;
rigidbody.useGravity=false;
transform.Translate ( Vector2(0, ClimbSpeed * Time.deltaTime));
DoubleJump = JumpReset;
}
if (Input.GetKey("s"))
{
//rigidbody.isKinematic = true;
rigidbody.velocity.y=0;
rigidbody.velocity.x=0;
rigidbody.useGravity=false;
transform.Translate (Vector2(0, -ClimbSpeed * Time.deltaTime));
DoubleJump = JumpReset;
}
                                if(Input.GetButtonDown("Jump"))
{
rigidbody.useGravity=true;
rigidbody.velocity.y=jump;
DoubleJump -= 1;
transform.rotation=Quaternion.identity;
}
}
}
function OnTriggerExit ( other : Collider)
{
if (other.gameObject.tag == "ladder")
{
//rigidbody.isKinematic = false;
rigidbody.useGravity=true;
transform.rotation = Quaternion.identity;
Climbing = false;
transform.parent = null;
}
if (other.gameObject.tag == "Mesh")
{
//rigidbody.isKinematic = false;
rigidbody.useGravity=true;
transform.rotation = Quaternion.identity;
Climbing = false;
transform.parent = null;
}
}
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

1274

主题

1

听众

4万

积分

禁止发言

纳金币
43676
精华
4
沙发
发表于 2011-8-12 21:34:02 |只看该作者
收藏了
回复

使用道具 举报

1023

主题

3

听众

359

积分

设计实习生

Rank: 2

纳金币
335582
精华
0

最佳新人

板凳
发表于 2011-12-30 18:22:24 |只看该作者
此地無銀。。。
回复

使用道具 举报

462

主题

1

听众

31万

积分

首席设计师

Rank: 8Rank: 8

纳金币
2
精华
0

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

地板
发表于 2012-1-28 23:32:06 |只看该作者
一帆风顺,二龙腾飞,三羊开泰,四季平安,五福临门,六六大顺,七星高照,八方来财,九九同心,十全十美。
回复

使用道具 举报

5969

主题

1

听众

39万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
0

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

5#
发表于 2012-2-19 23:29:26 |只看该作者
水。。。
回复

使用道具 举报

1023

主题

3

听众

359

积分

设计实习生

Rank: 2

纳金币
335582
精华
0

最佳新人

6#
发表于 2012-3-9 23:23:44 |只看该作者
我看看就走,你们聊!
回复

使用道具 举报

1023

主题

3

听众

359

积分

设计实习生

Rank: 2

纳金币
335582
精华
0

最佳新人

7#
发表于 2012-3-10 23:29:02 |只看该作者
不错哦,顶一下......
回复

使用道具 举报

tc    

5089

主题

1

听众

33万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
0

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

8#
发表于 2012-5-4 23:23:52 |只看该作者
再看一看,再顶楼主
回复

使用道具 举报

tc    

5089

主题

1

听众

33万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
0

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

9#
发表于 2012-6-14 23:25:06 |只看该作者
很经典,很实用,学习了!
回复

使用道具 举报

tc    

5089

主题

1

听众

33万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
0

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

10#
发表于 2012-6-29 23:25:10 |只看该作者
凡系斑竹滴话要听;凡系朋友滴帖要顶!
回复

使用道具 举报

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

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2025-7-27 23:31 , Processed in 0.083871 second(s), 28 queries .

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

© 2008-2019 Narkii Inc.

回顶部