- Home /
How to make a "player" or gameObject hover when idle?
I have my player (which is a ship) moving around on the x, y axis off the ground so it looks like it is flying through space but it does not look legit if there is no bobbing while it is idle in space. I would like it to just move ever so slightly like between 10.0 and 10.1 to get the feel like it's hovering in space rather then locked into place but when I push forward the bouncing stops
Answer by coolraiman · Jan 28, 2016 at 02:28 PM
if you want it to look natural you can always use a sine function to make it over on Y axis based on X time
http://jwilson.coe.uga.edu/EMAT6680Su07/Singer/Assignment%201/sine%20graph.html
and you could do something like this code where Y is your localPosition.Y and X = Time.DeltaTime
float y normalHeight = something;
void update()
{
if(state == state.Idle)
{
transform.localPosition = new Vector3(transform.localPosition.x, normalHeight + (theSineFormulaYouLike * Time.DeltaTime), transform.localPosition.y);
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612062041im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How can I create an atmosphere/oxygen system in my 3d space game. 1 Answer
Camera Shaking At High Speed 1 Answer
How do you make an orbit enemy ai? 0 Answers
How do i make floating ship ? 0 Answers
How to: Casting a ray cast 2 Answers