基于物理模型的动画 实验C#脚本

基于物理模型的动画 实验C#脚本

TestVelocity.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TestVelocity : MonoBehaviour {
	public Rigidbody rb;
	// Use this for initialization
	void Start () {
		rb = this.gameObject.AddComponent<Rigidbody> ();
		rb.useGravity = true;
		rb.mass = 1.0f;
		rb.drag = 0.0f;
	}
	
	// Update is called once per frame
	void Update () {
		//if(Input.GetButtonDown("Jump"))
		//rb.velocity=new Vector3(0.0f,10.0f,0.0f);
	}
	void FixedUpdate(){
		if (Input.GetButtonDown ("Jump"))
			rb.velocity = new Vector3 (0.0f, 10.0f, 0.0f);
	}
	void OnGUI(){
		GUILayout.Label ("Please press SPASE key...");
	}
}

TestAddForce

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TestAddForce : MonoBehaviour {
	public Rigidbody rb;
	public float thrust = 1.0f;
	// Use this for initialization
	void Start () {
		rb = gameObject.AddComponent<Rigidbody> () as Rigidbody;//rb=gameObject.AddComponent<Rigidbody>();
		rb.useGravity=true;
		rb.mass = 10.0f;
		rb.drag = 0.0f;
	}
	
	// Update is called once per frame
	void Update () {
		
	}

	void FixedUpdate(){
		//The following codes are used for testing Rigidbody.AddForce
		rb.AddForce(Vector3.forward* thrust,ForceMode.Force);
		//rb.AddForce(transform.forward* thrust,ForceMode.Force);//This will lead to different effect
		//Debug.log(transform.forward);

		//Try different ForceMode

		//rb.AddForce(Vector3.forward* thrust,ForceMode.Impulse);
		//rb.AddForce(transform.forward* thrust,ForceMode.Impulse);

		//rb.AddForce(Vector3.forward* thrust,ForceMode.Acceleration);
		//rb.AddForce(transform.forward* thrust,ForceMode.Acceleration);

		//rb.AddForce(Vector3.forward* thrust,ForceMode.VelocityChange);
		//rb.AddForce(transform.forward* thrust,ForceMode.Acceleration);

		//The following codes are used for testing Rigidbody.AddRelativeForce
		//rb.AddRelativeForce(Vector3.forward* thrust,ForceMode.Force);
		//rb.AddRelativeForce(transform.forward* thrust,ForceMode.Force);
		//rb.AddRelativeForce(Vector3.forward* thrust,ForceMode.Impulse);
	}
}

Ball.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Ball : MonoBehaviour {
	
	// Use this for initialization
	void Start () {
		this.GetComponent<Rigidbody> ().velocity = new Vector3 (-0.7f, 6.0f, 0.0f);
	}
	
	// Update is called once per frame
	void Update () {
		
	}
}

Launcher.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Launcher : MonoBehaviour {
	public GameObject ballPrefab;
	// Use this for initialization
	void Start () {

	}

	// Update is called once per frame
	void Update () {
		if (Input.GetMouseButtonDown (1)) {
			Instantiate (this.ballPrefab);
		}
	}
}

Player.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Launcher : MonoBehaviour {
	public GameObject ballPrefab;
	// Use this for initialization
	void Start () {

	}

	// Update is called once per frame
	void Update () {
		if (Input.GetMouseButtonDown (1)) {
			Instantiate (this.ballPrefab);
		}
	}
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
C#中,有几个Web3D引擎可以用于在Web应用程序中创建和展示3D图形。以下是一些常用的C# Web3D引擎: 1. Unity3D:Unity3D是一个跨平台的游戏引擎,也可以用于创建Web3D应用程序。它提供了一个强大的可视化编辑器和一套丰富的工具,可以创建复杂的3D场景、物体、动画等。你可以使用Unity的C#脚本来编写逻辑和交互代码,并将项目发布为WebGL格式以在浏览器中运行。 2. Babylon.js:Babylon.js是一个基于WebGL的开源Web3D引擎,专注于游戏和图形应用程序的开发。它提供了丰富的功能和API,可以创建复杂的3D场景、粒子效果、物理模拟等。Babylon.js使用TypeScript编写,但也可以与C#进行交互,例如使用Blazor框架。 3. Helix Toolkit:Helix Toolkit是一个.NET平台上的开源3D库,包含在WPF、Windows Forms和ASP.NET中使用的版本。它提供了一组易于使用的控件和工具,用于创建和显示3D场景、模型、光照效果等。你可以使用C#代码直接与Helix Toolkit进行交互。 除了以上列出的引擎外,还有其他一些Web3D引擎可以使用,如Three.js、Cesium等。尽管它们的主要开发语言不是C#,但你仍然可以使用C#与它们进行交互,例如通过JavaScript与C#之间的互操作性。 根据你的项目需求和技术偏好,选择适合的C# Web3D引擎来开发Web应用程序中的3D图形。在使用这些引擎之前,请确保阅读其文档和示例,了解如何正确地集成和使用它们。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值