本文整理汇总了C#中Vector3类的典型用法代码示例。如果您正苦于以下问题:C# Vector3类的具体用法?C# Vector3怎么用?C# Vector3使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Vector3类属于命名空间,在下文中一共展示了Vector3类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Rotate
void Rotate(float degreesAroundRight, float degreesAroundUp)
{
Quaternion rotation = Quaternion.Euler(-degreesAroundRight, degreesAroundUp, 0f);
transform.rotation = rotation;
Vector3 percheASelfie = new Vector3(0f, 0f, -_distance); // TODO: Move new outside of update
transform.position = rotation * percheASelfie;
}
示例2: Plane
public Plane(Vector3 n, float d)
: base((int)PrimitiveType.Plane)
{
JiggleMath.NormalizeSafe(ref n);
this.normal = n;
this.d = d;
}
示例3: Update
void Update()
{
// Get input vector from kayboard or analog stick and make it length 1 at most
Vector3 inputVector = new Vector3(0/*Input.GetAxis("Horizontal")*/, Input.GetAxis("Vertical"), 0);
if(1 < inputVector.magnitude) {
inputVector = inputVector.normalized;
}
inputVector = inputVector.normalized * Mathf.Pow(inputVector.magnitude, 2);
// Rotate input vector into camera space so up is camera's up and right is camera's right
inputVector = Camera.main.transform.rotation * inputVector;
// Rotate input vector to be perpendicular to character's up vector
Quaternion camToCharacterSpace = Quaternion.FromToRotation(Camera.main.transform.forward*-1, transform.up);
inputVector = (camToCharacterSpace * inputVector);
// Make input vector relative to Character's own orientation
inputVector = Quaternion.Inverse(transform.rotation) * inputVector;
if(walkMultiplier!=1) {
if( (Input.GetKey("left shift") || Input.GetKey("right shift")) != defaultIsWalk ) {
inputVector *= walkMultiplier;
}
}
//motor.desiredTurn = inputVector.x;
//inputVector.x = 0;
// Apply direction
motor.desiredMovementDirection = inputVector;
return;
}
示例4: SetObstacles
private void SetObstacles()
{
string modelName = "tree stomp sculpture";
float modelScale = 0.02f;
Vector3 initRot = new Vector3(-MathHelper.PiOver2, 0, 0);
Obstacles.Add(new BaseObject(RaceGame, modelName, Ground.Origin + new Vector3(29, 0, -8) * Ground.TerrainScale, modelScale, initRot));
Obstacles.Add(new BaseObject(RaceGame, modelName, Ground.Origin + new Vector3(63, 0, -18) * Ground.TerrainScale, modelScale, initRot));
Obstacles.Add(new BaseObject(RaceGame, modelName, Ground.Origin + new Vector3(101, 0, -13) * Ground.TerrainScale, modelScale, initRot));
Obstacles.Add(new BaseObject(RaceGame, modelName, Ground.Origin + new Vector3(101, 0, -19) * Ground.TerrainScale, modelScale, initRot));
Obstacles.Add(new BaseObject(RaceGame, modelName, Ground.Origin + new Vector3(111, 0, -20) * Ground.TerrainScale, modelScale, initRot));
Obstacles.Add(new BaseObject(RaceGame, modelName, Ground.Origin + new Vector3(94, 0, -31) * Ground.TerrainScale, modelScale, initRot));
Obstacles.Add(new BaseObject(RaceGame, modelName, Ground.Origin + new Vector3(15, 0, -36) * Ground.TerrainScale, modelScale, initRot));
Obstacles.Add(new BaseObject(RaceGame, modelName, Ground.Origin + new Vector3(111, 0, -43) * Ground.TerrainScale, modelScale, initRot));
Obstacles.Add(new BaseObject(RaceGame, modelName, Ground.Origin + new Vector3(50, 0, -50) * Ground.TerrainScale, modelScale, initRot));
Obstacles.Add(new BaseObject(RaceGame, modelName, Ground.Origin + new Vector3(106, 0, -53) * Ground.TerrainScale, modelScale, initRot));
Obstacles.Add(new BaseObject(RaceGame, modelName, Ground.Origin + new Vector3(57, 0, -55) * Ground.TerrainScale, modelScale, initRot));
Obstacles.Add(new BaseObject(RaceGame, modelName, Ground.Origin + new Vector3(98, 0, -62) * Ground.TerrainScale, modelScale, initRot));
Obstacles.Add(new BaseObject(RaceGame, modelName, Ground.Origin + new Vector3(75, 0, -68) * Ground.TerrainScale, modelScale, initRot));
Obstacles.Add(new BaseObject(RaceGame, modelName, Ground.Origin + new Vector3(28, 0, -69) * Ground.TerrainScale, modelScale, initRot));
Obstacles.Add(new BaseObject(RaceGame, modelName, Ground.Origin + new Vector3(42, 0, -69) * Ground.TerrainScale, modelScale, initRot));
Obstacles.Add(new BaseObject(RaceGame, modelName, Ground.Origin + new Vector3(81, 0, -78) * Ground.TerrainScale, modelScale, initRot));
Obstacles.Add(new BaseObject(RaceGame, modelName, Ground.Origin + new Vector3(13, 0, -85) * Ground.TerrainScale, modelScale, initRot));
Obstacles.Add(new BaseObject(RaceGame, modelName, Ground.Origin + new Vector3(103, 0, -89) * Ground.TerrainScale, modelScale, initRot));
Obstacles.Add(new BaseObject(RaceGame, modelName, Ground.Origin + new Vector3(73, 0, -90) * Ground.TerrainScale, modelScale, initRot));
Obstacles.Add(new BaseObject(RaceGame, modelName, Ground.Origin + new Vector3(49, 0, -92) * Ground.TerrainScale, modelScale, initRot));
Obstacles.Add(new BaseObject(RaceGame, modelName, Ground.Origin + new Vector3(37, 0, -101) * Ground.TerrainScale, modelScale, initRot));
Obstacles.Add(new BaseObject(RaceGame, modelName, Ground.Origin + new Vector3(106, 0, -53) * Ground.TerrainScale, modelScale, initRot));
Obstacles.Add(new BaseObject(RaceGame, modelName, Ground.Origin + new Vector3(120, 0, -121) * Ground.TerrainScale, modelScale, initRot));
Obstacles.Add(new BaseObject(RaceGame, modelName, Ground.Origin + new Vector3(24, 0, -122) * Ground.TerrainScale, modelScale, initRot));
for (int i = 0; i < Obstacles.Count; ++i)
{
RaceGame.Components.Add(Obstacles[i]);
}
}
示例5: SelfDestructor
public void SelfDestructor(int combo, bool b){
Combo.setCombo(combo);
rotate = true;
timer = 0f;
randomRot = new Vector3(Random.Range(-1f, 1f), Random.Range(-1f, 0f), Random.Range(-1f, 1f));
Destroy(gameObject, 20f);
}
示例6: Update
void Update()
{
if (!_First && _Velocity != 0)
{
float smooth = (_Velocity > 0) ? SmoothRate : -SmoothRate;
_Velocity -= smooth * Time.deltaTime;
if (Mathf.Abs(_Velocity) < 0.01f) _Velocity = 0f;
Vector3 move = new Vector3(_Velocity * -1, 0, 0);
_Transform.Translate(move, Space.World);
}
if (Input.GetMouseButton(0))
{
if (!_First)
{
DragEnter();
_First = true;
}
else
DragUpdate();
}
else if (Input.GetMouseButtonUp(0))
{
_First = false;
}
}
示例7: Update
// Update is called once per frame
void Update()
{
// transform.LookAt(transform.position + Camera.main.transform.rotation * Vector3.back,
// Camera.main.transform.rotation * Vector3.up);
//glowAmmount -= RATE * Time.deltaTime;
glowAmount = Mathf.Lerp(glowAmount, 0, RATE * Time.deltaTime);
if(glowAmount < 0)
glowAmount = 0;
//Debug.Log(glowAmmount * AMMOUNT);
// Color c = Color.blue;
// c.a = Mathf.Clamp01(glowAmmount * AMMOUNT);
//
// renderer.material.color = c;
//glowAmmount = 1.0f;
transform.LookAt(transform.position + previousVelocity);
GetComponent<ParticleSystem>().startSpeed = transform.parent.rigidbody.velocity.magnitude;
GetComponent<ParticleSystem>().emissionRate = glowAmount * AMOUNT - THRESHOLD;
//particleEmitter.Emit(Vector3.zero, previousVelosity, 1, 1, Color.white);
//particleEmitter.Emit(50);
previousVelocity = transform.parent.rigidbody.velocity;
}
示例8: Fire
public override void Fire(Vector3 direction, Quaternion rotation)
{
currentDistance = 0;
base.Fire(direction,rotation);
BulletProjectileUp();
amIFired = true;
}
示例9: Update
// Update is called once per frame
void Update()
{
offset = Vector3.Lerp(offset,Vector3.zero, 20f * Time.deltaTime);
transform.position = Vector3.Lerp(transform.position, player.transform.position, 1.0f * Time.deltaTime);
transform.position = new Vector3(transform.position.x,transform.position.y,-20f)+offset;
GetComponent<Camera>().orthographicSize = Screen.height / 128f;
}
示例10: MarchingCubesGo
void MarchingCubesGo()
{
MarchingCubes.SetTarget (marchingCubesThreshold);
MarchingCubes.SetWindingOrder(2, 1, 0);
MarchingCubes.SetModeToTetrahedrons();
MarchingCubes.SetScalar (voxelResolution);
Vector3 minExtantPos = Vector3.one * voxelCountPerChunk * chunkStride * -0.5f * voxelResolution;
for (int i = 0; i < chunkStride; i++) {
for (int j = 0; j < chunkStride; j++) {
for (int k = 0; k < chunkStride; k++) {
Vector3 start = new Vector3(i, j, k);
Vector3 end = start + Vector3.one;
start *= voxelCountPerChunk;
if (i > 0) start.x -= 1;
if (j > 0) start.y -= 1;
if (k > 0) start.z -= 1;
end *= voxelCountPerChunk;
end -= Vector3.one;
Mesh msh = MarchingCubes.CreateMesh (voxels, start, end);
msh.uv = new Vector2[msh.vertices.Length];
msh.RecalculateNormals();
msh.RecalculateBounds();
GameObject go = (GameObject)Instantiate (meshPrefab);
go.transform.position = minExtantPos;
go.GetComponent<MeshFilter> ().mesh = msh;
go.GetComponent<MeshCollider>().sharedMesh = msh;
}
}
}
}
示例11: UpdateWithCursor
////////////////////////////////////////////////////////////////////////////////////////////////
/*--------------------------------------------------------------------------------------------*/
internal void UpdateWithCursor(Vector3? pCursorPosition) {
if ( pCursorPosition == null || vIsAnimating ) {
HighlightProgress = 0;
vSelectionStart = null;
IsSelectionPrevented = false;
return;
}
if ( vCursorDistanceFunc == null ) {
throw new Exception("No CursorDistanceFunction has been set.");
}
if ( !NavItem.IsEnabled ) {
HighlightDistance = float.MaxValue;
HighlightProgress = 0;
return;
}
float dist = vCursorDistanceFunc((Vector3)pCursorPosition);
float prog = Mathf.InverseLerp(vSettings.HighlightDistanceMax,
vSettings.HighlightDistanceMin, dist);
HighlightDistance = dist;
HighlightProgress = prog;
}
示例12: CreateGrappleBeam
public bool IsHoldingGrapple = false; // if true the player is pulled alongwith the hook shot
public void CreateGrappleBeam() {
if (!IsGrappling) {
HandPosition = transform.position; // default for now
RaycastHit hit;
Player MyPlayer = gameObject.GetComponent<Player> ();
if (Physics.Raycast (transform.position, MyPlayer.ShootForwardVector, out hit, 100)) {
HandPosition = hit.point;
Quaternion NewRotation = new Quaternion ();
//NewRotation.eulerAngles = (hit.point - gameObject.transform.position);
NewRotation.eulerAngles = MyPlayer.ShootForwardVector;
NewRotation = Quaternion.identity;
//Debug.LogError ("Angle of Grapple: " + NewRotation.eulerAngles.ToString());
GameObject MyChain = (GameObject)Instantiate (GrappleBeamPrefab, HandPosition, NewRotation);
//NewRotation = MyChain.transform.rotation;
MyChain.transform.LookAt(hit.point);
//Debug.LogError ("Angle of Grapple: " + MyChain.transform.rotation.eulerAngles.ToString());
if (IsHoldingGrapple) {
//MyChain.transform.rotation = NewRotation;
transform.position = MyChain.transform.GetChild (7).transform.position;
Vector3 CharacterBodyOffset = new Vector3(0,-1.5f,0);
transform.position = transform.position+CharacterBodyOffset;
gameObject.AddComponent<FixedJoint> ();
gameObject.GetComponent<FixedJoint> ().connectedBody = MyChain.transform.GetChild (7).GetComponent<Rigidbody> ();
gameObject.GetComponent<CharacterController> ().enabled = false;
IsGrappling = true;
gameObject.GetComponent<Rigidbody>().isKinematic = false;
}
}
}
}
示例13: FixedUpdate
// Update is called once per frame
void FixedUpdate()
{
if (should_shoot) {
// did shoot before?
if (delay_active){
// enough time in between passed?
if (stopwatch.ElapsedMilliseconds > delay) {
stopwatch.Reset();
delay_active = false;
}
}else{
// shoot
Transform tmp = Instantiate(bullet, transform.position, Quaternion.identity) as Transform;
GameObject spawned_bullet = tmp.gameObject;
spawned_bullet.layer = this.gameObject.layer;
direction = (ship.transform.position - this.transform.position).normalized;
/*
// add spread
direction = new Vector3(direction.x + Random.Range(-accuarcy_spread, accuarcy_spread),
direction.y + Random.Range(-accuarcy_spread, accuarcy_spread),
direction.z + Random.Range(-accuarcy_spread, accuarcy_spread));
*/
spawned_bullet.transform.rotation = Quaternion.LookRotation(direction);
spawned_bullet.GetComponent<Rigidbody>().AddForce(direction * bullet_speed);
stopwatch.Start();
delay_active = true;
}
}
}
示例14: Start
// Use this for initialization
void Start()
{
for (int i = 0; i < this.transform.childCount; i++) {
GameObject obj = this.transform.GetChild(i).gameObject;
Animator animator = obj.GetComponentInChildren<Animator>();
this.animatorList.Add(animator);
obj.SetActive(false);
}
switch (showType) {
case ShowType.Enumeration: {
for(int i = 0; i < animatorList.Count; i++){
GameObject obj = animatorList[i].transform.parent.gameObject;
obj.SetActive(true);
float x = -20 + (i / 5) * 5;
float y = 10 - (i % 5) * 5;
Vector3 pos = new Vector3(x, y, i);
obj.transform.localPosition = pos;
}
break;
}
case ShowType.Queue: {
if(animatorList.Count >= 1){
currentAnimator = animatorList[0];
GameObject obj = currentAnimator.transform.parent.gameObject;
obj.SetActive(true);
}
break;
}
}
}
示例15: GetTarget
public static Obj_AI_Hero GetTarget(this Spell spell,
bool ignoreShields = true,
Vector3 from = default(Vector3),
IEnumerable<Obj_AI_Hero> ignoredChampions = null)
{
return TargetSelector.GetTarget(spell, ignoreShields, from, ignoredChampions);
}