moving an object in a circular motion based on the parent
I am trying to make an object move in a circular motion on an xand y play as it is a 2D game, but how would I do that: I have this
transform.Translate(0,0,Time.deltaTime*0.1); // move forward
transform.Rotate(0,Time.deltaTime*0.1,0); // turn a little
This works but I want to change the speed of it as well for differnet levels of my game so that is harder. e.g. at first it is slow but then in another scene it is faster than the first one. If anyone could help that would be great. Thanks in advance!!!
Answer by rodude123 · May 16, 2016 at 05:30 PM
this is what i figured out in the end
using UnityEngine;
using System.Collections;
public class circularMotion : MonoBehaviour {
public float RotateSpeed;
public float Radius;
public Vector2 centre;
public float angle;
private void Start()
{
centre = transform.position;
}
private void Update()
{
angle += RotateSpeed * Time.deltaTime;
var offset = new Vector2(Mathf.Sin(angle), Mathf.Cos(angle)) * Radius;
transform.position = centre + offset;
}
}
Your answer
Follow this Question
Related Questions
Changing the placement of circular motion in 2D? 1 Answer
How to drag object in X, Y, and Z axis with mouse. 0 Answers
How to make a curve motion change direction fluidly on click 0 Answers
How to convert x,y coordinates to an angle? 1 Answer
how to rotate y axis while circular motion,How to rotate while circular motion 0 Answers