本文整理汇总了C#中UnityEngine.Vector3类的典型用法代码示例。如果您正苦于以下问题:C# Vector3类的具体用法?C# Vector3怎么用?C# Vector3使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Vector3类属于UnityEngine命名空间,在下文中一共展示了Vector3类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FileToMesh
// Use this for initialization
public static Mesh FileToMesh(string filePath)
{
meshStruct newMesh = createMeshStruct(filePath);
populateMeshStruct(ref newMesh);
Vector3[] newVerts = new Vector3[newMesh.faceData.Length];
Vector2[] newUVs = new Vector2[newMesh.faceData.Length];
Vector3[] newNormals = new Vector3[newMesh.faceData.Length];
int i = 0;
/* The following foreach loops through the facedata and assigns the appropriate vertex, uv, or normal
* for the appropriate Unity mesh array.
*/
foreach (Vector3 v in newMesh.faceData)
{
newVerts[i] = newMesh.vertices[(int)v.x - 1];
if (v.y >= 1)
newUVs[i] = newMesh.uv[(int)v.y - 1];
if (v.z >= 1)
newNormals[i] = newMesh.normals[(int)v.z - 1];
i++;
}
Mesh mesh = new Mesh();
mesh.vertices = newVerts;
mesh.uv = newUVs;
mesh.normals = newNormals;
mesh.triangles = newMesh.triangles;
mesh.RecalculateBounds();
mesh.Optimize();
return mesh;
}
示例2: RotateTo
// Rotate this target towards a position
public void RotateTo(Vector3 position)
{
if (pivot == null) return;
if (pivot != lastPivot) {
defaultLocalRotation = pivot.localRotation;
lastPivot = pivot;
}
// Rotate to the default local rotation
pivot.localRotation = defaultLocalRotation;
// Twisting around the twist axis
if (twistWeight > 0f) {
Vector3 targetTangent = transform.position - pivot.position;
Vector3 n = pivot.rotation * twistAxis;
Vector3 normal = n;
Vector3.OrthoNormalize(ref normal, ref targetTangent);
normal = n;
Vector3 direction = position - pivot.position;
Vector3.OrthoNormalize(ref normal, ref direction);
Quaternion q = QuaTools.FromToAroundAxis(targetTangent, direction, n);
pivot.rotation = Quaternion.Lerp(Quaternion.identity, q, twistWeight) * pivot.rotation;
}
// Swinging freely
if (swingWeight > 0f) {
Quaternion s = Quaternion.FromToRotation(transform.position - pivot.position, position - pivot.position);
pivot.rotation = Quaternion.Lerp(Quaternion.identity, s, swingWeight) * pivot.rotation;
}
}
示例3: Start
void Start()
{
m_Cam = GetComponent<Camera>();
m_OriginalRotation = transform.localRotation;
this.UpdateAsObservable()
.Where(_ => GameState.Instance.GameStateReactiveProperty.Value == GameStateEnum.Countdown ||
GameState.Instance.GameStateReactiveProperty.Value == GameStateEnum.GameUpdate)
.Select(_ =>
{
var playerPos = PlayerManager.Instance.GetAlivePlayers()
.Select(x => x.transform.position);
var _x = playerPos.Average(x => x.x);
var _y = playerPos.Average(x => x.y);
var _z = playerPos.Average(x => x.z);
tergetPos = new Vector3(_x, _y, _z);
return tergetPos;
}).DelayFrame(3)
.Subscribe(target =>
{
var campos = tergetPos + m_defaultPosition;
transform.position = Vector3.Lerp(this.transform.position, campos, Time.deltaTime * 5.0f);
// transform.LookAt(target - this.transform.position);
});
}
示例4: FindHitPoint
public static Vector3 FindHitPoint(Vector3 origin)
{
Ray ray = Camera.main.ScreenPointToRay(origin);
RaycastHit hit;
if (Physics.Raycast(ray, out hit)) return hit.point;
return ResourseManager.InvalidPosition;
}
示例5: OnUpdate
public void OnUpdate()
{
_swipe = _down && Vector3.Distance(_startPosition, UnityEngine.Input.mousePosition) > 15;
_tapUnknown = !_tap && _tapUnknown;
_tap = _tapUnknown && Time.time - _tapUnknownTime > DoubleTapTimeout;
_doubleTap = false;
_longTap = false;
if (UnityEngine.Input.GetMouseButtonDown(0))
{
_tapStartTime = Time.time;
_startPosition = UnityEngine.Input.mousePosition;
_down = true;
}
if (UnityEngine.Input.GetMouseButtonUp(0))
{
_doubleTap = Time.time - _lastTapTime < DoubleTapTimeout;
_longTap = !_swipe && Time.time - _tapStartTime >= LongTapTimeout;
_tapUnknown = !(_swipe || _doubleTap || _longTap);
_tapUnknownTime = _tapUnknown ? Time.time : 0;
_lastTapTime = Time.time;
_down = false;
}
if (_tap || _longTap || _doubleTap)
{
_result = new TouchResult(_startPosition);
}
if (_swipe)
{
_result = new TouchResult(UnityEngine.Input.mousePosition);
}
}
示例6: RigidbodyRotateAround
// Rotate a rigidbody around a point and axis by angle
protected void RigidbodyRotateAround(Vector3 point, Vector3 axis, float angle)
{
Quaternion rotation = Quaternion.AngleAxis(angle, axis);
Vector3 d = transform.position - point;
r.MovePosition(point + rotation * d);
r.MoveRotation(rotation * transform.rotation);
}
示例7: Awake
private Vector3 newPos; // The position the camera is trying to reach.
//private int check = 1;
void Awake ()
{
// Setting up the reference.
//player = GameObject.FindGameObjectWithTag ("Player");
// Setting the relative position as the initial relative position of the camera in the scene.
newPos = new Vector3 (9.39f, 12f, -2f);
}
示例8: GetComposition
public Dictionary<int, PhysSoundComposition> GetComposition(Vector3 contactPoint)
{
foreach (PhysSoundComposition c in compDic.Values)
c.Reset();
float[] mix = getTextureMix(contactPoint);
for (int i = 0; i < mix.Length; i++)
{
if (i >= SoundMaterials.Count)
break;
if (SoundMaterials[i] == null)
continue;
PhysSoundComposition comp;
if (compDic.TryGetValue(SoundMaterials[i].MaterialTypeKey, out comp))
{
comp.Add(mix[i]);
}
}
return compDic;
}
示例9: Vertex
public Vertex(Vector3 pos, Vector3 normal)
{
//this.pos = (pos != Vector3.zero) ? pos : Vector3.zero;
this.pos = pos;
//this.normal = (normal != Vector3.zero) ? normal : Vector3.zero;
this.normal = normal;
}
示例10: SetWaypoint
public virtual void SetWaypoint(Vector3 destination)
{
currentWaypoint = destination;
isTurning = true;
isMoving = false;
targetEntityGameObject = null;
}
示例11: GetPointAlongLine
public Vector3 GetPointAlongLine(Vector3 point1, Vector3 point2, float magnitude)
{
Vector3 line = point2 - point1;
line = line.normalized * magnitude;
line = line + point1;
return line;
}
示例12: Add
// private int colMinCoordinate, rowMinCoordinate, colMaxCoordinate, rowMaxCoordinate;
public void Add(Vector3 coordinates, HexField hex)
{
// Vector2 offsetCoordinates;
// if (isEven) {
// offsetCoordinates = HexMath.ConvertCubeToEvenROffsetCoordinate ((int)coordinates.x, (int)coordinates.y, (int)coordinates.z);
// } else {
// offsetCoordinates = HexMath.ConvertCubeToOddROffsetCoordinate ((int)coordinates.x, (int)coordinates.y, (int)coordinates.z);
// }
// if (this.hexList.Count == 0) {
// colMinCoordinate = (int)offsetCoordinates.x;
// colMaxCoordinate = (int)offsetCoordinates.x;
// rowMinCoordinate = (int)offsetCoordinates.y;
// rowMaxCoordinate = (int)offsetCoordinates.y;
// }
// if (offsetCoordinates.x < colMinCoordinate) {
// colMinCoordinate = (int)offsetCoordinates.x;
// } else if (offsetCoordinates.x > colMaxCoordinate) {
// colMaxCoordinate = (int)offsetCoordinates.x;
// }
// if (offsetCoordinates.y < rowMinCoordinate) {
// rowMinCoordinate = (int)offsetCoordinates.y;
// } else if (offsetCoordinates.y > rowMaxCoordinate) {
// rowMaxCoordinate = (int)offsetCoordinates.y;
// }
hex.SetCoordinates(coordinates);
this.hexList.Add(coordinates , hex);
hex.SetListenerList(this.listenerList);
}
示例13: GetAngleAxis
public static void GetAngleAxis(this Quaternion q, out Vector3 axis, out float angle)
{
if (q.w > 1) q = QuaternionUtil.Normalize(q);
//get as doubles for precision
var qw = (double)q.w;
var qx = (double)q.x;
var qy = (double)q.y;
var qz = (double)q.z;
var ratio = System.Math.Sqrt(1.0d - qw * qw);
angle = (float)(2.0d * System.Math.Acos(qw)) * Mathf.Rad2Deg;
if (ratio < 0.001d)
{
axis = new Vector3(1f, 0f, 0f);
}
else
{
axis = new Vector3(
(float)(qx / ratio),
(float)(qy / ratio),
(float)(qz / ratio));
axis.Normalize();
}
}
示例14: Update
// Update is called once per frame
void Update()
{
// Update water level
Level = Mathf.Clamp01(Level);
TopShape.localPosition = new Vector3(0, Level - 0.5f, 0);
float newTopScale = Mathf.Sqrt(0.25f - Mathf.Pow (Level - 0.5f, 2))*2;
TopShape.localScale = new Vector3(newTopScale, 0.0001f, newTopScale);
r.material.SetTextureOffset("_MainTex", new Vector2(0, 0.25f-Mathf.Asin((Level-0.5f)/0.5f)/2f/Mathf.PI));
// Tilt
Vector3 accel = new Vector3();
Vector3 pos;
if (UseRootMotion) {
pos = transform.position;
Math3d.LinearAcceleration(out accel, pos, 2); // require Math 3D script
accel.x *= axisAdjust.x;
accel.y *= axisAdjust.y;
accel.z *= axisAdjust.z;
} else {
pos = Root.transform.InverseTransformPoint(transform.position);
Math3d.LinearAcceleration(out accel, pos, 2); // require Math 3D script
accel.x *= axisAdjust.x;
accel.y *= axisAdjust.y;
accel.z *= axisAdjust.z;
accel = Root.transform.TransformDirection(accel);
}
Vector3 gModified = new Vector3(-accel.x, Gravity-accel.y, -accel.z);
Vector3 angularAccel = Vector3.Cross(-transform.up, gModified) * Acceleration; // (torque = F tangetial x r)
AngularVelocity += angularAccel * Time.deltaTime;
AngularVelocity *= Damp;
transform.RotateAround(transform.position, AngularVelocity, AngularVelocity.magnitude * Time.deltaTime);
Accel = accel;
}
示例15: Move
public void Move(Vector3 move, bool crouch, bool jump)
{
// convert the world relative moveInput vector into a local-relative
// turn amount and forward amount required to head in the desired
// direction.
if (move.magnitude > 1f) move.Normalize();
move = transform.InverseTransformDirection(move);
CheckGroundStatus();
move = Vector3.ProjectOnPlane(move, m_GroundNormal);
m_TurnAmount = Mathf.Atan2(move.x, move.z);
m_ForwardAmount = move.z;
ApplyExtraTurnRotation();
// control and velocity handling is different when grounded and airborne:
if (m_IsGrounded)
{
HandleGroundedMovement(crouch, jump);
}
else
{
HandleAirborneMovement();
}
ScaleCapsuleForCrouching(crouch);
PreventStandingInLowHeadroom();
// send input and other state parameters to the animator
UpdateAnimator(move);
}