// Update is called once per frame void Update() { Vector2 player_pos = FindObjectOfType <BabyCowScript>().transform.position; if (cur_state == CowState.Idle) { Vector2 pos = transform.position; transform.position = new Vector3(pos.x, pos.y - speed * Time.deltaTime, -3); if (Vector2.Distance(player_pos, gameObject.transform.position) < flock_range) { cur_state = CowState.Following; FindObjectOfType <BabyCowScript>().AddScore(1); } } if (cur_state == CowState.Following) { if (Vector2.Distance(player_pos, gameObject.transform.position) < flock_range) { gameObject.transform.rotation = Quaternion.RotateTowards(rgbd.transform.rotation, Quaternion.Euler(0, 0, master_angle), rot_rate); rgbd.transform.Translate(Vector3.up * master_speed); } else { float rot_val = 180 * Mathf.Atan((player_pos.y - rgbd.transform.position.y) / (player_pos.x - rgbd.transform.position.x)) / Mathf.PI; rot_val = player_pos.x - rgbd.transform.position.x < 0 ? rot_val + 90 : rot_val - 90; gameObject.transform.rotation = Quaternion.RotateTowards(rgbd.transform.rotation, Quaternion.Euler(0, 0, rot_val), 5.0f); rgbd.transform.Translate(Vector3.up * master_speed); } } }
public IPickable Pickup(IEntity entity) { if (_pickedUpBy != null) { return(null); } if (_boxCollider) { _boxCollider.isTrigger = true; } if (_sphereCollider) { _sphereCollider.isTrigger = true; } // _rb.detectCollisions = false; _rb.velocity = Vector3.zero; _rb.angularVelocity = Vector3.zero; _rb.constraints = RigidbodyConstraints.FreezeAll; _pickedUpBy = entity; var t = transform; t.localRotation = Quaternion.identity; t.SetParent(entity.GetObject().GetComponentInChildren <RightArmTarget>().transform); t.localRotation = Quaternion.identity; transform.localRotation = Quaternion.Euler(0, -90, 0); return(this); }
public void rotateCameras() { if (Input.touchCount >= 2) { Touch touch0 = Input.GetTouch(0); Touch touch1 = Input.GetTouch(1); if (touch1.phase == TouchPhase.Moved) { float pinchAmount = 0; Quaternion desiredRotation = transform.rotation; CalculateCamRotation(); if (Mathf.Abs(turnAngleDelta) > 0) { // rotate Vector3 rotationDeg = Vector3.zero; rotationDeg.z = -turnAngleDelta; desiredRotation *= Quaternion.Euler(rotationDeg); } transform.rotation = desiredRotation; transform.position += Vector3.forward * pinchAmount; } } }
/* * This function allows users to rotate * before placing a block * and to rotate a selected block * with keys. * Makes block rotation persistent * Makes block rotation persistent * between placements */ public void RotateKeys(bool CW) // or left { int angle = 90; if (CW) { angle *= -1; } // ok. Ik this is weird, but hear me out: currentRotation = Quaternion.Euler(0f, currentRotation + angle, 0f).eulerAngles.y; GameObject toRotate = null; if (GhostBlock != null) { toRotate = GhostBlock; } else if (_selected != null) { toRotate = _selected; } else { // nothing to rotate return; } toRotate.GetComponent <Qubit>().SetRotation(currentRotation); }
private void RotateViaQuat(Vector3 targPos) { Vector3 turretPivotDir = targPos - turretPivot.position; Vector3 cannonPivotDir = targPos - cannonPivot.position; Quaternion turretPivotLookRot = Quaternion.LookRotation(turretPivotDir); Quaternion cannonPivotLookRot = Quaternion.LookRotation(cannonPivotDir); Vector3 turretDirY = new Vector3(0f, turretPivotLookRot.eulerAngles.y - 90f, 0f); Vector3 cannonDirY = new Vector3(0f, 0f, -cannonPivotLookRot.eulerAngles.x); Vector3 turretDirSmoothing = new Vector3(0f, Mathf.MoveTowards(turretPivot.eulerAngles.y, turretDirY.y, Owner.StateMachineOwner.ThisStats.GetRotationSpeed), 0f); Vector3 cannonDirSmoothing = new Vector3(0f, 0f, Mathf.MoveTowards(cannonPivot.eulerAngles.z, cannonDirY.z, Owner.StateMachineOwner.ThisStats.GetRotationSpeed)); Quaternion turretYRot = Quaternion.Euler(turretDirSmoothing); Quaternion cannonYRot = Quaternion.Euler(cannonDirSmoothing); turretPivot.rotation = turretYRot; cannonPivot.rotation = cannonYRot; // Not sure why this is happening, try and figure it out eventually i guess, just fixes the child rotation back // to 0 Vector3 cannonPivotLocalEuler = cannonPivot.localEulerAngles; cannonPivot.localEulerAngles = new Vector3(0f, 0f, cannonPivotLocalEuler.z); }
private void OnMouseDown() { if (_moving) { return; } if (_firingPosition) { if (_primed) { Fire(); } return; } var o = PlayerController.Instance.Take("Gunpowder"); if (o == null) { return; } FacilitatorScript.Instance.Hide(); StartCoroutine(_moveCannon(firingPosition.position, Quaternion.Euler(Vector3.Scale(Quaternion.LookRotation(GameManager.Instance.EnemyPosition - transform.position).eulerAngles, Vector3.up)), MoveTime)); _firingPosition = true; _primed = true; }
public void UpdateRotation(float rotation) { float x = lastObj.transform.rotation.x; float z = lastObj.transform.rotation.z; lastObj.transform.rotation = Quaternion.Euler(new Vector3(x, rotation, z)); }
/// <summary> /// Create a new MoverServiceRequest with the current values of the robot's joint angles, /// the target cube's current position and rotation, and the targetPlacement position and rotation. /// /// Call the MoverService using the ROSConnection and if a trajectory is successfully planned, /// execute the trajectories in a coroutine. /// </summary> public void PublishJoints() { GotoServiceRequest request = new GotoServiceRequest(); request.joints_input = CurrentJointConfig(); if (targetX == 0 && targetY == 0 && targetZ == 0) { request.target_pose = new RosMessageTypes.Geometry.Pose { position = (target.transform.position + pickPoseOffset).To <FLU>(), // The hardcoded x/z angles assure that the gripper is always positioned above the target cube before grasping. orientation = Quaternion.Euler(90, target.transform.eulerAngles.y, 0).To <FLU>() }; } else { float Xpose = targetX * 0.3f; float Ypose = (targetY * 0.15f) + 0.75f; float Zpose = targetZ * 0.225f; request.target_pose = new RosMessageTypes.Geometry.Pose { position = (new Vector3(Xpose, Ypose, Zpose) + pickPoseOffset).To <FLU>(), // The hardcoded x/z angles assure that the gripper is always positioned above the target cube before grasping. orientation = Quaternion.Euler(90, target.transform.eulerAngles.y, 0).To <FLU>() }; } // Pick Pose ros.SendServiceMessage <GotoServiceResponse>(rosServiceName, request, TrajectoryResponse); }
void DoFallingAction() { // Keep updating position of closest while flying as long as we find tether points if (FindClosestTetherPoint(gos) != null) { tetherTransform = FindClosestTetherPoint(gos).transform; } // Move indicator to the closest tether point indicatorGameObject.transform.position = new Vector3(tetherTransform.position.x, tetherTransform.position.y + indicatorOffset, 0f); // Move sphere away from screen indicatorSphere.transform.position = new Vector3(0f, -1.0f, 0f); // Update player rotation while flying Vector3 direction = rb.velocity.normalized; float rotationZ = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg; if (rb.velocity != Vector3.zero) { transform.rotation = Quaternion.Euler(0f, 0f, rotationZ - (360.0f)); } // Called only once if (Input.GetMouseButtonUp(0)) { releaseSound.Play(0); // Disable sound soundplayed = false; // Destroy HingeJoints Destroy(joint); Destroy(anchorJoint); // Hide rope lr.enabled = false; } }
private void SpawnAgent(GameObject agentPrefab) { var spawnPos = Random.insideUnitCircle * spawnRadius * density; var rotation = Quaternion.Euler(UnityEngine.Vector3.forward * Random.Range(0f, 360f)); Instantiate(agentPrefab, spawnPos, rotation, transform); }
public IEnumerator PlaceStreetPositions(Vector3 startPosition, Vector3Int direction, int length) { var rotation = Quaternion.identity; if (direction.x == 0) { rotation = Quaternion.Euler(0, 90, 0); } for (int i = 0; i < length; i++) { var position = Vector3Int.RoundToInt(startPosition + direction * i); if (roadDictionary.ContainsKey(position)) { continue; } var road = Instantiate(roadStraight, position, rotation, transform); road.AddComponent <FallTween>(); roadDictionary.Add(position, road); if (i == 0 || i == length - 1) { fixRoadCandidates.Add(position); } yield return(new WaitForSeconds(animationTime)); } finishedCoroutine?.Invoke(); }
private void OnTriggerExit2D(Collider2D other) { if (other.gameObject.CompareTag("Player") && other.GetType() != typeof(BoxCollider2D)) { //return the players gravity to normal rbPlayer.gravityScale = 0.1f; //Declares an upright rotation Quaternion target = Quaternion.Euler(0, 0, 0); //Rotates the player to upright while (Quaternion.Angle(player.transform.rotation, target) > 0) { player.transform.rotation = Quaternion.Slerp(player.transform.rotation, target, Time.deltaTime * smooth); } //Sets that the player has left the planet radius playerController.Attracted = false; //Gives the player a boost as they leave the planet radius var outDir = GetDirection(planetBody.transform.position, player.transform.position) * 5; rbPlayer.AddForce(outDir, ForceMode2D.Force); virtualCamera.Priority = 10; } }
private void BuildTop(Vector3 pos, int currentFloor, int towersIndex) { Instantiate(groundPrefabs[Random.Range(0, groundPrefabs.Length)], pos + Vector3.up * currentFloor * _heightFloor - Vector3.up * 0.5f, Quaternion.Euler(0, Random.Range(0, 6) * 60, 0), _towers[towersIndex].transform); }
public void Publish() { NiryoMoveitJoints sourceDestinationMessage = new NiryoMoveitJoints(); sourceDestinationMessage.joint_00 = jointArticulationBodies[0].xDrive.target; sourceDestinationMessage.joint_01 = jointArticulationBodies[1].xDrive.target; sourceDestinationMessage.joint_02 = jointArticulationBodies[2].xDrive.target; sourceDestinationMessage.joint_03 = jointArticulationBodies[3].xDrive.target; sourceDestinationMessage.joint_04 = jointArticulationBodies[4].xDrive.target; sourceDestinationMessage.joint_05 = jointArticulationBodies[5].xDrive.target; // Pick Pose sourceDestinationMessage.pick_pose = new RosMessageTypes.Geometry.Pose { position = target.transform.position.To <FLU>(), orientation = Quaternion.Euler(90, target.transform.eulerAngles.y, 0).To <FLU>() }; // Place Pose sourceDestinationMessage.place_pose = new RosMessageTypes.Geometry.Pose { position = targetPlacement.transform.position.To <FLU>(), orientation = pickOrientation.To <FLU>() }; // Finally send the message to server_endpoint.py running in ROS ros.Send(topicName, sourceDestinationMessage); }
private void RotateCamera() { if (Input.GetMouseButtonDown(2)) { dragOrigin = Input.mousePosition; return; } if (!Input.GetMouseButton(2)) { return; } Vector3 pos = Camera.main.ScreenToViewportPoint(Input.mousePosition - dragOrigin); Vector3 currentRot = transform.rotation.eulerAngles; Vector3 newRot = new Vector3(0, pos.x * rotateSpeed, 0); cameraFollowPoint.transform.Rotate(newRot); newRot.x = -pos.y * rotateSpeed; newRot += currentRot; //newRot = transform.InverseTransformDirection(newRot); Quaternion newQuat = Quaternion.Euler(newRot); transform.rotation = newQuat; }
private void SummonBullet(int BulletIndex, float CertainSpeed) { Vector3 RelativeSumPoint = new Vector3(SummonPoint.x * GetComponent <Collider2D>().bounds.size.x, SummonPoint.y * GetComponent <Collider2D>().bounds.size.y, 0); Vector3 position; Quaternion rotation; bool FacingRight = GetComponent <PlayerController>().FacingRight; if (FireDirection.y < 0 && FireDirection.x == 0) { position = FacingRight ? transform.position + RelativeSumPoint : transform.position + Vector3.Reflect(RelativeSumPoint, Vector3.right); } else { position = _aimindic.transform.position; } rotation = FacingRight ? Quaternion.Euler(0f, 0f, Vector2.SignedAngle(Vector2.right, FireDirection)) : Quaternion.Euler(0f, 180f, Vector2.SignedAngle(FireDirection, Vector2.left)); var bulletInstance = Instantiate(Bullets[BulletIndex], position, rotation); bulletInstance.GetComponent <Rigidbody2D>().velocity = CertainSpeed * FireDirection; bulletInstance.gameObject.GetComponent <BulletInfo>().playerOrigin = gameObject; }
public void GenerateFetchedObjects(int roomId, GameObject parent, RotateText loadingText = null) { if (loadingText != null) { loadingText.StartRotation("Loading Objects..."); } RestClient.Get <RoomPlan>($"{_urlBase}/RoomPlans/{roomId}").Then(roomPlan => { foreach (var wallBlock in roomPlan.wallBlocks) { GameObject wallInstance = Instantiate(_wallPrefab, new Vector3(wallBlock.positionX * scalePosX, 0, wallBlock.positionY * scalePosY), Quaternion.Euler(0, wallBlock.rotation, 0)); // wallInstance.transform.localScale = new Vector3(1f, 1, 1f); wallInstance.transform.parent = parent.transform; } if (loadingText != null) { loadingText.StopRotation(); } //move parent root parent.transform.Translate(-1.5f, -0.5f, -1.5f); }).Catch(error => { if (loadingText != null) { loadingText.StartRotation(error.Message); } }); }
private void UpdatePos() { try { Vector3 pos = this.m_tank.transform.position; Vector3 rot = this.m_tank.transform.eulerAngles; float distance = (pos - this.m_nPos).magnitude; // 如果服务器位置与本地位置相差不到0.1f,就不进行移动 if (Mathf.Abs(distance) < 0.1f) { return; } // 从当前位置向预测位置移动 if (this.m_delta > 0) { this.m_tank.transform.position = Vector3.Lerp(pos, this.m_fPos, this.m_delta); this.m_tank.transform.rotation = Quaternion.Lerp(Quaternion.Euler(rot), Quaternion.Euler(this.m_fRot), this.m_delta); } } catch (Exception e) { Log.Error("Update" + e); } }
public void IsTouched() { if (IsInTouch) { return; } MaxForceApplied = false; Ball.GetComponent <CircleCollider2D>().isTrigger = false; NavCircle.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 0)); Ball.gameObject.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 0)); _touchPosWorld = Camera.main.ScreenToWorldPoint(Input.mousePosition); // maps touch poisition to screen pos RaycastHit2D hitMe = Physics2D.Raycast(_touchPosWorld, Vector2.zero); // hit raycast directly on the point where user touches. if (hitMe.collider != null) //if collider hits sometihing { if (hitMe.collider.CompareTag("ball")) { IsInTouch = true; BallTouched = true; _startPos = Ball.transform.position; RigidBodyBall.drag = .5f; RigidBodyBall.angularDrag = .5f; Ball.transform.GetChild(0).gameObject.SetActive(false); Debug.Log("Ball is Touched"); } } }
// Update is called once per frame public void CalculateShape(float R1, float R2, int nCircles, int samples) { this.nCircles = nCircles; this.samples = samples; shape = new List <Vector2>(); nCircles = Math.Max(1, nCircles); float angleArc; var d = R1 * Mathf.Sin(Mathf.PI / nCircles); R2 = Mathf.Max(R2, d); { var h = Mathf.Sqrt(R2 * R2 - d * d); var beta = Mathf.Rad2Deg * Mathf.Atan2(h, d); float gamma = 360 - (nCircles - 2) * 180 / nCircles; angleArc = gamma - 2 * beta; } shape = new List <Vector2>(); for (int i = 0; i < nCircles; i++) { DrawArc(i, Quaternion.Euler(0, 360.0f / nCircles * i, 0) * Vector3.forward * R1, R2, angleArc); } //Repeat first point shape.Add(shape[0]); shape.Reverse(); }
private void ShowPickups() { foreach (var pickup in pickups) { Vector3 position = pickup.Position.GetVector3(); Vector3 angle = pickup.Angle.GetVector3(); Vector3 scale = pickup.Scale.GetVector3(); scale.Scale(new Vector3(1.0f / 32.0f, 1.0f / 32.0f, 1.0f / 32.0f)); angle.Scale(new Vector3(180f, 180f, 180f)); position.y += scale.y / 2f; GameObject item; switch (pickup.ModelName) { case "crate_fruit": item = Instantiate(fruitCrate, position, Quaternion.Euler(angle.x, angle.y, angle.z)); item.transform.localScale = scale; break; case "crate_question": item = Instantiate(itemCrate, position, Quaternion.Euler(angle.x, angle.y, angle.z)); item.transform.localScale = scale; break; case "itemFruit": item = Instantiate(itemFruit, position, Quaternion.Euler(angle.x, angle.y, angle.z)); item.transform.localScale = scale; break; } } }
// Start is called before the first frame update // Update is called once per frame void Update() { //Rotating the camerra around the board to focuse on the current player var currSide = tPlayer.currSpot.GetComponent <WalkableScript>().side; if (currSide == Boardside.Left) { cameraOffset.z = -2; cameraOffset.x = 0; } else if (currSide == Boardside.Bottom) { cameraOffset.z = 0; cameraOffset.x = 2; } else if (currSide == Boardside.Top) { cameraOffset.z = 0; cameraOffset.x = -2; } else if (currSide == Boardside.Right) { cameraOffset.z = 2; cameraOffset.x = 0; } Vector3 dPosition = target.position + cameraOffset; Vector3 sPosition = Vector3.SmoothDamp(transform.position, dPosition, ref velocity, smoothSpeed); transform.position = sPosition; Quaternion dRotation = Quaternion.Euler(25, (int)currSide, 0); transform.rotation = Quaternion.Slerp(transform.rotation, dRotation, Time.deltaTime * smoothSpeed); }
private void LoadTrains() { foreach (var trainRide in apiManager.TrainRides) { LoadCities(trainRide); Point firstPoint = trainRide.points[0]; Train train = MakeTrain( trainRide.trainRideId, trainRide.train.trainType == "Pendolino"?TrainTypes.Pendolino:TrainTypes.Thomans, new Vector3(Consts.mapScale * (float)firstPoint.latitude, cityHeight, Consts.mapScale * (float)firstPoint.longitude) ); foreach (var user in apiManager.GetTrainUsers(trainRide.trainRideId)) { bool isPlayer = user.userId == apiManager.userId; Wagon wagon = train.AddWagon(isPlayer); if (isPlayer) { Camera.main.transform.SetParent(wagon.transform); Camera.main.transform.position = new Vector3(-10, 10, -6); Camera.main.transform.rotation = Quaternion.Euler(20, 50, 0); cameraDrag.target = train; customizationManager.myWagon = wagon; customizationManager.Fetch(); } } TrainPath path = new TrainPath(); path.points = beziers; train.FollowPath(path); trains.Add(train); } }
void ServerMove(Vector3 ownerPos, float velX, float velZ, bool jumping, float rotY, uLink.NetworkMessageInfo info) { if (info.sender != networkView.owner || info.rawServerTimestamp <= serverLastTimestamp) { return; } Vector3 rot = transform.rotation.eulerAngles; transform.rotation = Quaternion.Euler(rot.x, rotY, rot.z); if (velX * velX + velZ * velZ > sqrMaxServerSpeed) { velX = velZ = Mathf.Sqrt(sqrMaxServerSpeed) * 0.5f; } float deltaTime = (float)(info.rawServerTimestamp - serverLastTimestamp); Vector3 deltaPos = new Vector3(velX * deltaTime, 0, velZ * deltaTime); if (wasGrounded && canJump && jumping) { lastVelY = Mathf.Sqrt(2 * jumpHeight * gravityAcceleration); wasGrounded = false; } character.Move(deltaPos); serverLastTimestamp = info.rawServerTimestamp; serverHasLastOwnerPos = true; serverLastOwnerPos = ownerPos; }
private static void LoadMapGroup(MapGroup group, GameObject parent = null) { if (group.groupName.Contains("fnc0000")) { return; } GameObject groupRootObject = new GameObject(group.groupName); if (parent == null) { groupRootObject.GetComponent <Transform>().position = Vector3.Reflect(group.groupTransform.translation, Vector3.left); groupRootObject.GetComponent <Transform>().rotation = Quaternion.Euler(Vector3.Reflect(group.groupTransform.rotation.ToVector3(), Vector3.left)); groupRootObject.GetComponent <Transform>().localScale = Vector3.Reflect(group.groupTransform.scale, Vector3.left); } else { groupRootObject.GetComponent <Transform>().SetParent(parent.GetComponent <Transform>()); groupRootObject.GetComponent <Transform>().localPosition = group.groupTransform.translation; groupRootObject.GetComponent <Transform>().localRotation = group.groupTransform.rotation; groupRootObject.GetComponent <Transform>().localScale = group.groupTransform.scale; } groupRootObject.SetActive(true); if (group.entries != null && group.entries.Count > 0) { foreach (MapModelEntry entry in group.entries) { if (DebugCustomLoad) { if (!debugCustomLoadList.Contains(entry.modelId)) { continue; } } Mesh[] meshes = _modelMeshes[entry.modelId]; GameObject obj = AddMeshToNewGameObject(meshes, true); obj.GetComponent <Transform>().SetParent(groupRootObject.GetComponent <Transform>()); obj.GetComponent <Transform>().localPosition = entry.transform.translation; obj.GetComponent <Transform>().localRotation = entry.transform.rotation; obj.GetComponent <Transform>().localScale = entry.transform.scale; obj.SetActive(true); } } if (group.groups != null && group.groups.Count > 0) { foreach (MapGroup subGroup in group.groups) { if (subGroup != null) { LoadMapGroup(subGroup, groupRootObject); } } } }
private static Vector3 RotatePointAroundPivot(Vector3 point, Vector3 pivot, Vector3 angles) { var dir = point - pivot; // get point direction relative to pivot dir = Quaternion.Euler(angles) * dir; // rotate it point = dir + pivot; // calculate rotated point return(point); // return it }
/// <summary> /// Event when the projectile collides with the ground. /// </summary> /// <param name="other">object the projectile collides with</param> private void OnCollisionEnter(Collision other) { Instantiate(_splash, transform.position, Quaternion.Euler(270f, 0f, 0f)); if (other.gameObject.CompareTag("Ground")) { StartCoroutine(Wait()); } }
// Update is called once per frame void Update() { Vector3 currEuler = this.transform.rotation.eulerAngles; Vector3 direction = (int)this.m_Direction * this.m_DegreeSpeed * Time.deltaTime * new Vector3(0, 0, 1); Vector3 newEuler = currEuler + direction; this.transform.rotation = Quaternion.Euler(newEuler); }
private void PerformRotation() { //Récupération de la rotation + on empeche la camera de touner en 360 rb.MoveRotation(rb.rotation * Quaternion.Euler(rotation)); currentCameraRotationX -= camerarotationX; currentCameraRotationX = Mathf.Clamp(currentCameraRotationX, -cameraRotationLimit, cameraRotationLimit); cam.transform.localEulerAngles = new Vector3(currentCameraRotationX, 0f, 0f); }
/// <summary> /// Tower rotates to the target found, to then fire a bullet in that direction. /// </summary> private void RotateToTarget() { Vector3 direction = _targetFinder.target.transform.position - transform.position; Quaternion lookRotation = Quaternion.LookRotation(direction); Vector3 rotation = Quaternion.Lerp(_rotation.rotation, lookRotation, Time.deltaTime * 10).eulerAngles; _rotation.rotation = Quaternion.Euler(0f, rotation.y, 0f); }