void Start() { ancienPos = obj.transform.position; posVoulu = ancienPos + vue; this.transform.position = posVoulu; y_start = transform.position.y; }
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; }
public Plane(Vector3 n, float d) : base((int)PrimitiveType.Plane) { JiggleMath.NormalizeSafe(ref n); this.normal = n; this.d = d; }
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; }
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]); } }
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); }
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; } }
// 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; }
public override void Fire(Vector3 direction, Quaternion rotation) { currentDistance = 0; base.Fire(direction,rotation); BulletProjectileUp(); amIFired = true; }
// 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; }
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; } } } }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ 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; }
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; } } } }
// 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; } } }
// 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; } } }
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); }
// Update is called once per frame private void Update() { Vector3 targetPosition = target.position; targetPosition.x = Mathf.Clamp(targetPosition.x, BoundsMin.x, BoundsMax.x); targetPosition.y = Mathf.Clamp(targetPosition.y, BoundsMin.y, BoundsMax.y); // only update lookahead pos if accelerating or changed direction float xMoveDelta = (targetPosition - m_LastTargetPosition).x; bool updateLookAheadTarget = Mathf.Abs(xMoveDelta) > lookAheadMoveThreshold; if (updateLookAheadTarget) { m_LookAheadPos = lookAheadFactor*Vector3.right*Mathf.Sign(xMoveDelta); } else { m_LookAheadPos = Vector3.MoveTowards(m_LookAheadPos, Vector3.zero, Time.deltaTime*lookAheadReturnSpeed); } Vector3 aheadTargetPos = targetPosition + m_LookAheadPos + Vector3.forward*m_OffsetZ; Vector3 newPos = Vector3.SmoothDamp(transform.position, aheadTargetPos, ref m_CurrentVelocity, damping); transform.position = newPos; m_LastTargetPosition = targetPosition; }
public void Update() { if (Input.GetMouseButtonDown(0) && SpaceTraderConfig.LocalPlayer && SpaceTraderConfig.LocalPlayer.Ship) { var pos = new Vector3(Input.mousePosition.x, Input.mousePosition.y); var ray = SpaceTraderConfig.WorldMap.Camera.ScreenPointToRay(pos); RaycastHit hit; if (Physics.Raycast(ray, out hit, float.PositiveInfinity, LayerMask.GetMask("World Map"))) { //the only things on this layer with colliders should be markers var mapArea = hit.collider.GetComponent<WorldMapMarker>().Area; SpaceTraderConfig.LocalPlayer.Ship.Target = mapArea.GetComponent<Targetable>(); Debug.Log("targetted area " + mapArea); } } float eastWest = Input.GetAxis("yaw"); float northSouth = Input.GetAxis("pitch"); const float PAN_SPEED = 50; camOffset += PAN_SPEED * Time.deltaTime * new Vector3(eastWest, 0, northSouth); var lerped = Vector3.Lerp(mapCamera.transform.position, camOffset, 2 * Time.deltaTime); var camXform = mapCamera.transform; camXform.position = lerped; }
private ScoreboardController _scoreboardController; // hold reference to ScoreboardController #endregion Fields #region Methods IEnumerator SpawnWaves() { yield return new WaitForSeconds(startWait); while (true) { for (int i = 0; i < hazardCount; i++) { Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z); Quaternion spawnRotation = Quaternion.identity; // spawn with no rotation, this is already defined in RandomRotator.cs Instantiate(hazard, spawnPosition, spawnRotation); yield return new WaitForSeconds(spawnWait); } yield return new WaitForSeconds(waveWait); if (_scoreboardController.IsGameOver()) { _scoreboardController.restartLabel.text = "Press 'R' to Restart"; _scoreboardController.SetRestart(true); break; } } }
public Vector3 Add(ref Vector3 v) { return new Vector3( x: x + v.x, y: y + v.y, z: z + v.z); }
public bool TakeDamage(int amount, Vector3 hitPoint) { // If the enemy is dead... if (isDead) // ... no need to take damage so exit the function. return false; // Play the hurt sound effect. //enemyAudio.Play(); // Reduce the current health by the amount of damage sustained. currentHealth -= amount; healthPercent = Mathf.CeilToInt((currentHealth * 1.0f) / (startingHealth) * 100); // Set the position of the particle system to where the hit was sustained. //hitParticles.transform.position = hitPoint; // And play the particles. //hitParticles.Play(); // If the current health is less than or equal to zero... if (currentHealth <= 0) { // ... the enemy is dead. Death(); return true; } return false; }
private void Awake() { button = transform.FindChild("Button"); thebase = transform.FindChild("Base"); startScale = button.localScale; targetScale = thebase.localScale; }
// Update is called once per frame void Update() { this.transform.position += Velocity*Time.deltaTime; if (transform.position.x < -384) { Velocity = new Vector3(200.0f, Velocity.y, 0); } if (transform.position.x > 384) { Velocity = new Vector3(-200.0f, Velocity.y, 0); } if (pointer.renderer.enabled == false) { if (transform.position.y > 640) { pointer.rotation = Quaternion.Euler (0, 0, 0); pointer.renderer.enabled = true; controls.p1Wins++; StartCoroutine("timeout"); } else if (transform.position.y < -640) { pointer.rotation = Quaternion.Euler (0, 0, 180); pointer.renderer.enabled = true; controls.p2Wins++; StartCoroutine("timeout"); } } }
float CalculatePathLength(Vector3 targetPosition) { // Create a path and set it based on a target position. NavMeshPath path = new NavMeshPath(); if (nav.enabled) nav.CalculatePath(targetPosition, path); // Create an array of points which is the length of the number of corners in the path + 2. Vector3[] allWayPoints = new Vector3[path.corners.Length + 2]; // The first point is the enemy's position. allWayPoints[0] = transform.position; // The last point is the target position. allWayPoints[allWayPoints.Length - 1] = targetPosition; // The points inbetween are the corners of the path. for (int i = 0; i < path.corners.Length; i++) { allWayPoints[i + 1] = path.corners[i]; } // Create a float to store the path length that is by default 0. float pathLength = 0; // Increment the path length by an amount equal to the distance between each waypoint and the next. for (int i = 0; i < allWayPoints.Length - 1; i++) { pathLength += Vector3.Distance(allWayPoints[i], allWayPoints[i + 1]); } return pathLength; }
/// <summary> /// Checks the mouse's position set in the in-game world plane. /// </summary> /// <param name="mousePosition">Mouse's position on screen</param> /// <param name="camera">Camera object</param> /// <param name="device">Graphics device used in rendering</param> /// <returns></returns> public static Vector3 getMouseWorldPosition(Vector2 mousePosition,CameraAndLights camera,GraphicsDevice device) { Vector3 nearsource = new Vector3(mousePosition,0f); Vector3 farsource = new Vector3(mousePosition,CameraAndLights.nearClip); Vector3 nearPoint = device.Viewport.Unproject(nearsource, camera.projectionMatrix, camera.viewMatrix, Matrix.Identity); Vector3 farPoint = device.Viewport.Unproject(farsource, camera.projectionMatrix, camera.viewMatrix, Matrix.Identity); // Create a ray from the near clip plane to the far clip plane. Vector3 direction = farPoint - nearPoint; direction.Normalize(); Ray pickRay = new Ray(nearPoint,direction); Plane floor = new Plane(new Vector3(0f,1f,0f),0f); float denominator = Vector3.Dot(floor.Normal,pickRay.Direction); float numerator = Vector3.Dot(floor.Normal,pickRay.Position) + floor.D; float dist = -(numerator / denominator); Vector3 mouseWorldPos = nearPoint + direction * dist; return mouseWorldPos * new Vector3(1f,0f,1f); }
void FixedUpdate() { //have we moved more than our minimum extent? Vector3 movementThisStep = myRigidbody.position - previousPosition; float movementSqrMagnitude = movementThisStep.sqrMagnitude; if (movementSqrMagnitude > sqrMinimumExtent) { float movementMagnitude = Mathf.Sqrt(movementSqrMagnitude); RaycastHit hitInfo; //check for obstructions we might have missed if (Physics.Raycast(previousPosition, movementThisStep, out hitInfo, movementMagnitude, layerMask.value)) { if (!hitInfo.collider) return; if (this.GetComponent<Collider>().isTrigger) this.SendMessage("OnTriggerEnter", hitInfo.collider); if (hitInfo.collider.isTrigger) hitInfo.collider.SendMessage("OnTriggerEnter", myCollider); if (!hitInfo.collider.isTrigger) myRigidbody.position = hitInfo.point - (movementThisStep / movementMagnitude) * partialExtent; } } previousPosition = myRigidbody.position; }
public void LookAt(Vector3 destination) { float tempX = transform.rotation.eulerAngles.x; transform.LookAt(destination); // compensating mesh flaw, it's awful, but it's works transform.rotation = Quaternion.Euler(tempX, transform.rotation.eulerAngles.y, transform.rotation.eulerAngles.z); }
public void DrawAttkBox(SPoint[] v, string mat, int n, int endN, SPoint p, int pNum, int t, int poly) { //specialized manual function for attackboxes subMesh [poly] = new Mesh (); int vTot = endN - n + 1; Vector3[] vertices = new Vector3[vTot]; Color32[] col = new Color32[vTot]; //std::stringstream hbName; string hbName = "P#" + pNum + "HB-" + t + "-" + poly; for (int i = n; i <= endN; i++) { vertices [i-n] = new Vector3 (v [i].x + p.x, v [i].y + p.y, 0); col [i-n] = new Color32 (0, 250, 20, 150); } int tTot = (vTot - 2) * 3; int[] tri = new int[tTot]; for (int i = 0; i<(tTot/3);i++) {//triangle fan tri[i*3]=0; tri[(i*3)+1]=i+1; tri[(i*3)+2]=i+2; } subMesh[poly].vertices=vertices; subMesh[poly].triangles = tri; subMesh[poly].colors32 = col; }
public Plane(Vector3 n, Vector3 pos) : base((int)PrimitiveType.Plane) { JiggleMath.NormalizeSafe(ref n); this.normal = n; this.d = -Vector3.Dot(n, pos); }
// Update is called once per frame void FixedUpdate() { if(BallRef) { //DISTANCE DistanceToTarget = Vector3.Distance(transform.position, BallRef.transform.position); //GET MOVE TO LOCATION if(BallRef.GetComponent<Rigidbody>().velocity.normalized == Vector3.zero) { MoveToLocation = BallRef.position + new Vector3(0f,0f,-2.5f); } else { MoveToLocation = BallRef.position + ((BallRef.GetComponent<Rigidbody>().velocity.normalized) * -2.5f); } MoveToLocation += (Vector3.up * 2); //MOVE transform.position = Vector3.Lerp(transform.position, MoveToLocation, Time.deltaTime * (DistanceToTarget/3)); //LOOK AT Vector3 relativePos = (BallRef.transform.position + Vector3.up) - transform.position; Quaternion rotation = Quaternion.LookRotation(relativePos); transform.rotation = rotation; } }