Question by
unity_aNstF6-_tmM8gQ · Dec 14, 2018 at 04:05 PM ·
movementmove
semicircular movement
How to semicircular movement between to points , A to B and back to A. semicircular movement not circle movement
this code for circle movment
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Degress : MonoBehaviour {
public float radius = 2f; //Distance from the center of the circle to the edge
public float currentAngle= 0f; //Our angle, this public for debugging purposes
private float speed = 0f; //Rate at which we'll move around the circumference of the circle
public float timeToCompleteCircle = 1.5f; //Time it takes to complete a full circle
// Use this for initialization
void Start () {
}
void Awake(){
speed = (Mathf.PI * 2) / timeToCompleteCircle;
}
// Update is called once per frame
void Update () {
speed = (Mathf.PI * 2) / timeToCompleteCircle; //For level design purposes
currentAngle += Time.deltaTime * speed; //Changes the angle
float newX = radius * Mathf.Sin (currentAngle);
float newY = radius * Mathf.Cos (currentAngle);
transform.position = new Vector3 (newX, newY ,transform.position.z);
}
}
Comment
Your answer
Follow this Question
Related Questions
What is the correct way to move objects relative to each other ? 1 Answer
My player moves diagonally when you press two keys at once 0 Answers
How to move an object with a starting and ending speed and time 0 Answers
How to move an object left and right by dragging mouse after clicking left mouse button. 0 Answers
Is ther a way to base movement translation through the grid map of the tilemap? 1 Answer