Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unity3D Notes #11

Open
dabing1022 opened this issue Oct 11, 2015 · 1 comment
Open

Unity3D Notes #11

dabing1022 opened this issue Oct 11, 2015 · 1 comment

Comments

@dabing1022
Copy link
Owner

1.Look towards player
using UnityEngine;
using System.Collections;

public class LookTowardMouse : MonoBehaviour {

     void Update () 
     {
         //Mouse Position in the world. It's important to give it some distance from the camera. 
         //If the screen point is calculated right from the exact position of the camera, then it will
         //just return the exact same position as the camera, which is no good.
         Vector3 mouseWorldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition + Vector3.forward * 10f);

         //Angle between mouse and this object
         float angle = AngleBetweenPoints(transform.position, mouseWorldPosition);

         //Ta daa
         transform.rotation =  Quaternion.Euler (new Vector3(0f,0f,angle));
     }

     float AngleBetweenPoints(Vector2 a, Vector2 b) {
         return Mathf.Atan2(a.y - b.y, a.x - b.x) * Mathf.Rad2Deg;
     }  
 }
@dabing1022
Copy link
Owner Author

  • 当RigidBody2D的质量属性被设置为0时,刚体的质量变为无限大,此时刚体相当于静态刚体,永远一动不动。但是在Unity中你是无法把一个RigidBody2D的质量设置为0的,所以,当你想创建一个静态刚体时,只需要创建碰撞器,而不需要创建RigidBody2D。
  • 当我们勾选了is Kenamatic选项时,这个RigidBody2D就不再受物理引擎控制,我们这时候需要通过Transform来控制RigidBody2D的移动,这个选项经常在脚本里对其进行设置。
  • 当Gravity Scale设置为0时,该刚体不再受重力影响。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant