- Home /
Using Float and Mathf
//I'm following a book which refers to MonoDevelop, and to my understanding this should make the sphere move and spiral, But it does nothing. Perhaps I am missing something? Or does using a different IDE make a difference? Or is there another approach? I am 100% new to programming, So please if it's obviously just state so. Thanks
using UnityEngine; using System.Collections;
public class sphereController : MonoBehaviour {
public float Control;
public float OtherControl = 5;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.position = new Vector3
{
x = Mathf.Sin(Control) * OtherControl,
y = Mathf.Cos(Control) * OtherControl,
z = Control * OtherControl
};
}
}
Answer by tpusch · Dec 14, 2015 at 12:15 AM
The sphere won't move because Control
and OtherControl
are never changing. Depending on how you want to move the ball you can add something like this to Update.
void Update(){
transform.position = new Vector3
{
x = Mathf.Sin(Control) * OtherControl,
y = Mathf.Cos(Control) * OtherControl,
z = Control * OtherControl
};
Control += Time.deltaTime;
}
Your answer
Follow this Question
Related Questions
Mathf.Lerp float between 0 and 1 based on boolean input 3 Answers
Periodic fraction gets converted to int 1 Answer
Comparing float value to zero 1 Answer
float precision, again 0 Answers