Vector3nextObjectPosition = transform.position So, here before we move the second object, we need to store the first object position. So, now second object should be moved on first object position, third object should be moved on second object position, forth object should be moved on third object position and so on. If we move the first object we have to move the whole chain. Step 6 Set current position & rotation to next object Continue until touch is not ended.Ĭhain movement stops when touch is ended. If the first object is detected then step-2 to step-6 are executed in Update(). Chain will move when the first object is detected from those objects array. Here, I got an array of all the objects in range of radius 1 at touch position using Physics2D.OverlapCircleAll() function. If(Vector2.Distance (transform.position, currentTouch) >distanceBetweenTwoPart) designate distance than call Move() method again if distance between object & touch position is greater than SnakePart.MoveSnakePart(nextPartPosition, nextPartRotation) pass position & rotation to next object Transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.Euler (0, 0, targetAngle), 30f * ltaTime) Transform.position= Vector2.Lerp(transform.position, currentPosition, ltaTime * Constants.SPEED) įloattargetAngle = GetAngle(moveDirection) Vector3nextPosition = currentPosition+(moveDirection * distanceBetweenTwoPart) Find next position at designate distance between 2 object MoveDirection = Utility.GetDirection(currentTouch, currentPosition) QuaternionnextPartRotation = transform.localRotation ĬurrentTouch = (mousePos) Vector3nextPartPosition = transform.position Vector3cameraPosition = (Input.mousePosition) Ĭollider2D others = Physics2D.OverlapCircleAll(cameraPosition, 1) There are different logics for detecting objects out of which I have explained about circle overlapping. Compare your highest score with your friends to see who the best player is.Begin detecting the first object of the chain on touch.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |