本文整理汇总了C#中Vector3.Normalize方法的典型用法代码示例。如果您正苦于以下问题:C# Vector3.Normalize方法的具体用法?C# Vector3.Normalize怎么用?C# Vector3.Normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector3
的用法示例。
在下文中一共展示了Vector3.Normalize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetActualSteer
public Vector3 GetActualSteer(Vector3 desiredSteer)
{
Forces forces = mAttributes.Forces;
float mag = desiredSteer.magnitude;
if (mag < forces.MinSpeed)
{
desiredSteer.Normalize();
desiredSteer *= forces.MinSpeed;
}
if (mag > forces.MaxSpeed)
{
desiredSteer.Normalize();
desiredSteer *= forces.MaxSpeed;
}
float maxRateRadians = Mathf.Deg2Rad * forces.TurnRateDegrees * Time.deltaTime;
Vector3 actualSteer = Vector3.RotateTowards(transform.forward, desiredSteer, maxRateRadians, forces.MaxSpeed);
//transform.rotation = Quaternion.LookRotation(actualSteer, transform.up);
{
Vector3 desiredSteerNormalized = desiredSteer;
desiredSteerNormalized.Normalize();
Vector3 actualSteerNormalized = actualSteer;
actualSteerNormalized.Normalize();
const float factor = 50.0f;
Debug.DrawLine(transform.position, transform.position + (desiredSteerNormalized * factor), Color.red);
Debug.DrawLine(transform.position, transform.position + (actualSteerNormalized * factor), Color.green);
}
return actualSteer;
}
示例2: BallFold
private static Vector3 BallFold(float r, Vector3 v)
{
float len = v.Len();
if (len < r) return v.Normalize(len / (r * r));
else if (len < 1) return v.Normalize(1 / len);
return v;
}
示例3: GetBodySegmentAngle
/// <summary>
/// Calculates the angle between the segments of the body defined by the specified joints.
/// </summary>
/// <param name="joints"></param>
/// <param name="joint1"></param>
/// <param name="joint2">Must be between joint1 and joint3</param>
/// <param name="joint3"></param>
/// <returns>The angle in degrees between the specified body segmeents.</returns>
public double GetBodySegmentAngle(JointCollection joints)
{
Joint joint1 = joints[_JointId1.JointType];
Joint joint2 = joints[_JointId2.JointType];
Joint joint3 = joints[_JointId3.JointType];
Vector3 vectorJoint1ToJoint2 = new Vector3(joint1.Position.X - joint2.Position.X, joint1.Position.Y - joint2.Position.Y, 0);
Vector3 vectorJoint2ToJoint3 = new Vector3(joint2.Position.X - joint3.Position.X, joint2.Position.Y - joint3.Position.Y, 0);
vectorJoint1ToJoint2.Normalize();
vectorJoint2ToJoint3.Normalize();
Vector3 crossProduct = Vector3.Cross(vectorJoint1ToJoint2, vectorJoint2ToJoint3);
double crossProductLength = crossProduct.Z;
double dotProduct = Vector3.Dot(vectorJoint1ToJoint2, vectorJoint2ToJoint3);
double segmentAngle = Math.Atan2(crossProductLength, dotProduct);
// Convert the result to degrees.
double degrees = segmentAngle * (180 / Math.PI);
// Add the angular offset. Use modulo 360 to convert the value calculated above to a range
// from 0 to 360.
degrees = (degrees + _RotationOffset) % 360;
// Calculate whether the coordinates should be reversed to account for different sides
if (_ReverseCoordinates)
{
degrees = CalculateReverseCoordinates(degrees);
}
return degrees;
}
示例4: Reflect
public void Reflect(Collider coll, Vector3 reflDir)
{
if (coll.attachedRigidbody && coll.gameObject.layer == LayerMask.NameToLayer("Bullet"))
{
GameObject refl = Instantiate<GameObject>(bulletPrefab);
refl.gameObject.tag = "SpawnedBullet";
refl.transform.position = coll.transform.position;
Vector3 vel;
vel = reflDir;
vel.Normalize();
BulletBase reflBase = refl.GetComponent<BulletBase>();
refl.GetComponent<Rigidbody>().velocity = vel * reflBase.bulletSpeed;
reflBase.ignoreEnemies = false;
reflBase.rend.material = reflBase.reflectMat;
Destroy(coll.gameObject);
}
else if (coll.attachedRigidbody)
{
Vector3 vel;
vel = reflDir * coll.GetComponent<Rigidbody>().velocity.magnitude;
coll.GetComponent<Rigidbody>().velocity = vel;
}
}
示例5: Move
public void Move(float horizontal, float vertical)
{
if (!AIManager.staticManager.EndGame)
{
//velocity += new Vector3(horizontal, 0, vertical) * accel;
/*if (Mathf.Abs(horizontal) < deadzone) horizontal = 0;
if (Mathf.Abs(vertical) < deadzone) vertical = 0;
if (horizontal > 3) horizontal = 3;
if (vertical > 3) vertical = 3;*/
velocity += new Vector3(horizontal, 0f, vertical).normalized * accel * accel;
if (velocity.magnitude > maxVel)
{
velocity.Normalize();
velocity *= maxVel;
}
velocity -= velocity.normalized * drag;
if (horizontal == 0 && vertical == 0 && velocity.magnitude < drag) velocity *= 0;
transform.position = new Vector3(transform.position.x + velocity.x * Time.deltaTime, transform.position.y, transform.position.z + velocity.z * Time.deltaTime);
anim.SetFloat("Speed", velocity.magnitude);
Rotate();
}
}
示例6: Update
// Update is called once per frame
public override void Update()
{
//rotate
transform.Rotate(0f, Input.GetAxis("Mouse X") * turnSpeed * Time.deltaTime, 0f); //turnSpeed is an absolute rotation
//movement
// create a new vector for move which takes input values
move = new Vector3(Input.GetAxis("Horizontal"), 0f, Input.GetAxis("Vertical"));
//normalize the vector first so that it moves at a consistent speed in all directions
move.Normalize();
//before we call update, convert move to the direction our player is facing by using transformDirection
//takes the local movement along x,y,z into a global movement
move = transform.TransformDirection(move);
//check if player wants to jump
if (Input.GetKey(KeyCode.Space) && control.isGrounded )
{
jumping = true;
}
running = Input.GetKey(KeyCode.LeftShift);
base.Update();
}
示例7: Update
public override void Update(GameTime gameTime)
{
Matrix collisionworld = Matrix.Identity;
collisionworld *= tank1.world;
if (this.CollidesWith(tank1.model, collisionworld))
{
}
else
{
float distanceTotank1Position;
float speed = 2;
tankEnemyPosition = world.Translation;
direction = tank1.world.Translation - tankEnemyPosition;
direction.Normalize();
Vector3 tankVelocity = speed * direction;
distanceTotank1Position = Vector3.Distance(tank1.world.Translation, tankEnemyPosition);
float timeTotank1Position = distanceTotank1Position / speed;
Vector3 target = tank1.world.Translation;
Vector3 targeDirection = target - tankEnemyPosition;
targeDirection.Normalize();
enemyPursueMove = targeDirection * speed;
world *= Matrix.CreateTranslation(enemyPursueMove);
}
}
示例8: Update
// Update is called once per frame
void Update()
{
Vector3 movement = new Vector3(Input.GetAxis ("Horizontal"), 0, 0);
movement = movement;
movement.Normalize();
controller.SimpleMove(movement * speed);
}
示例9: SteeringBehaviours
public SteeringBehaviours(Fighter entity)
{
this.fighter = entity;
calculationMethod = CalculationMethods.WeightedTruncatedRunningSumWithPrioritisation;
sphere = new Sphere(0.2f);
XNAGame.Instance().Children.Add(sphere);
wanderTarget = new Vector3(randomClamped(), randomClamped(), randomClamped());
wanderTarget.Normalize();
weights.Add(behaviour_type.allignment, 1.0f);
weights.Add(behaviour_type.cohesion, 2.0f);
weights.Add(behaviour_type.obstacle_avoidance, 20.0f);
weights.Add(behaviour_type.wall_avoidance, 20.0f);
weights.Add(behaviour_type.wander, 1.0f);
weights.Add(behaviour_type.seek, 1.0f);
weights.Add(behaviour_type.flee, 1.0f);
weights.Add(behaviour_type.arrive, 1.0f);
weights.Add(behaviour_type.pursuit, 1.0f);
weights.Add(behaviour_type.offset_pursuit, 1.0f);
weights.Add(behaviour_type.interpose, 1.0f);
weights.Add(behaviour_type.hide, 1.0f);
weights.Add(behaviour_type.evade, 0.01f);
weights.Add(behaviour_type.follow_path, 1.0f);
weights.Add(behaviour_type.separation, 1.0f);
}
示例10: SetDirection
// 지정한 방향으로 향한다.
public void SetDirection(Vector3 direction)
{
forceRotateDirection = direction;
forceRotateDirection.y = 0;
forceRotateDirection.Normalize();
forceRotate = true;
}
示例11: Update
// Update is called once per frame
void Update()
{
// move in horizontal pane
float x = -Input.GetAxis("Horizontal");
float y = -Input.GetAxis("Vertical");
Vector3 cameraMovement = new Vector3(x, 0f, y);
cameraMovement.Normalize();
cameraMovement *= cameraSpeed;
transform.Translate(cameraMovement * Time.deltaTime, Space.World);
// set height
float cameraRotation = 0;
float zoomChange = Input.GetAxis("Mouse ScrollWheel");
cameraHeight += zoomChange * zoomHeightSpeed * Time.deltaTime;
cameraRotation = zoomChange * zoomRotationSpeed * Time.deltaTime;
cameraSpeed += zoomChange * zoomCameraAccelerationSpeed * Time.deltaTime;
Vector3 cameraPosition = transform.position;
cameraPosition.y = Terrain.activeTerrain.SampleHeight(transform.position) + cameraHeight;
cameraPosition.z += zoomChange * zoomRailSpeed * Time.deltaTime;
transform.Rotate(cameraRotation, 0, 0, Space.World);
transform.position = cameraPosition;
}
示例12: Update
void Update()
{
Vector3 currentPosition = transform.position;
time++;
if (pauseShoot)
{
if (time % 50 == 0 && bullets < 5)
{
bullets++;
BulletsManager.Reload(1);
}
}
if (pauseShoot)
{
if (bullets > 0)
{
if (Input.GetButtonDown("Fire1"))
{
Vector3 moveToward = Camera.main.ScreenToWorldPoint(Input.mousePosition);
moveDirection = moveToward - currentPosition;
moveDirection.z = 0;
moveDirection.Normalize();
GameObject projectile = (GameObject)Instantiate(bullet[Random.Range(0,3)], firePosition.position, firePosition.rotation);
projectile.GetComponent<Rigidbody2D>().velocity = moveDirection * speed;
bullets--;
BulletsManager.PlayerShot(1);
}
}
}
}
示例13: FixedUpdate
void FixedUpdate()
{
if(controller.levelFinished || controller.currentState == 0)
{
rigidbody.velocity = Vector3.zero;
rigidbody.angularVelocity = Vector3.zero;
return;
}
Vector3 direction = new Vector3(Input.GetAxis("Horizontal"),0,Input.GetAxis("Vertical"));
if(direction.magnitude > 1.0) direction.Normalize();
if(direction.magnitude > 0){
// lets set the direction according to the camera now.
direction = Camera.main.transform.TransformDirection(direction) * speed * 2;
// lets take the downward velocity from the current so that we dont get wierd physics results
direction.y = rigidbody.velocity.y;
// Now, lets keep track of a velocity.
// This will let the ball move while we are not pressing anything.
rigidbody.velocity = Vector3.Lerp(rigidbody.velocity, direction, 3.0f * Time.deltaTime);
// Now, lets break the rotation out from the movement.
Vector3 rotation = new Vector3(rigidbody.velocity.z,0,-rigidbody.velocity.x) * 20;
// Lets add some spin to make the ball move better
rigidbody.angularVelocity = Vector3.Lerp(rigidbody.angularVelocity, rotation, 3.0f * Time.deltaTime);
}
}
示例14: AddForce
void AddForce(Vector3 vector, Vector3 rotation)
{
vector.Normalize();
vector.y = 1f;
selfTf.eulerAngles = rotation;
m_rigidbody.AddForce(vector * -1, ForceMode.VelocityChange);
}
示例15: Draw
public override void Draw(GameTime gameTime)
{
RasterizerState rs = new RasterizerState();
rs.CullMode = CullMode.None;
device.RasterizerState = rs;
viewMatrix = Game1.Instance.Camera.getView();
projectionMatrix = Game1.Instance.Camera.getProjection();
Matrix worldMatrix = Matrix.Identity;
effect.CurrentTechnique = effect.Techniques["Colored"];
effect.Parameters["xView"].SetValue(viewMatrix);
effect.Parameters["xProjection"].SetValue(projectionMatrix);
effect.Parameters["xWorld"].SetValue(worldMatrix);
Vector3 lightDirection = new Vector3(1.0f, -1.0f, -1.0f);
lightDirection.Normalize();
effect.Parameters["xLightDirection"].SetValue(lightDirection);
effect.Parameters["xAmbient"].SetValue(0.1f);
effect.Parameters["xEnableLighting"].SetValue(true);
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
device.Indices = myIndexBuffer;
device.SetVertexBuffer(myVertexBuffer);
device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertices.Length, 0, indices.Length / 3);
}
base.Draw(gameTime);
}