- Home /
How can i translate my object?
Hi All,
I am working on projectile motion. In that there is a button called throw. if i click throw button the ball object going projectile. In that i got maxheight. by using this code i am getting the height.
string height = GUI.TextField(new Rect(Screen.width-85, 10, 75, 25), (maxHeight).ToString());
if (maxHeight < (Projectile.transform.position.y - transform.position.y )){
maxHeight = ( Projectile.transform.position.y - transform.position.y );
}
After got max height i have a scale. I below of the scale there is sphere type of object. I want to pass that object into max height point.
i mean if i got maxHeight = 6.5 then that sphere i want to movie vertically same height.
for that i wrote code.
using UnityEngine;
using System.Collections;
public class Tran : MonoBehaviour {
public GameObject game;
void Start () {
}
void Update()
{
game.transform.Translate(game.transform.position.x,(game.transform.position.y+ThrowSimulation.maxHeight), game.transform.position.z);
}
}
But it is showing error. after playing my application that is automatically came into scenemode. If i write the custom method also not working properly.
And my task is when ever the throw is complete. i want to show my maxheight by using that sphere in that scale. please help me
thanks in advance
Navadeep
you need to scale your sphere or translate? you can use transform.localScale
for scaling
No.. no.. scale is just static object. i want to translate sphere(vertically) depending upon that max height.
Answer by Sanky · May 06, 2013 at 06:53 AM
do you want to transform game object so you have to try this
public class Tran : MonoBehaviour { public Transform game; int treee; void Start () { } void Update() { game.transform.position=new Vector3(game.transform.position.x,game.transform.position.y+2,game.transform.position.z); } }
Sanky, Thanks for your help. the problem is that the sphere is not getting to rest at the particular height.
using UnityEngine;
using System.Collections;
public class Tran : $$anonymous$$onoBehaviour {
public GameObject game;
void Update(){
game.transform.position=new Vector3(game.transform.position.x,game.transform.position.y+ThrowSimulation.maxHeight,game.transform.position.z);
}
}
I wrote the code above. I want to stop at maxheight. but that is going.......
Your answer
Follow this Question
Related Questions
When I throw the projectile, it triggers the land collision before landing on it 0 Answers
Scale using accelerometer with limits 0 Answers
Scale using accelerometer with limits 0 Answers
The floating point origin and AI 1 Answer
VR Scale/Move 0 Answers