Quantcast
Channel: Answers by "Superrodan"
Viewing all articles
Browse latest Browse all 62

Answer by Superrodan

$
0
0
Then this should be extremely simple. All you need to do is create a script that moves the object downwards every frame. Here is a quick and dirty example that uses a speed per second: public float groundHeight; public float startHeight; public float speedToDropAt; private bool go =true; void Start() { //Start by finding my current position and storing it temporarily. Vector3 startPosition = this.gameObject.transform.localPosition; //Now change the height of that position to where I want my object to start. startPosition.y = startHeight; //Now sets my actual position to the stored version with the new height. this.gameObject.transform.localPosition = startPosition; } void Update() { //Check if I should start moving if(go==true) { //Check if I have reached the ground yet. if(this.gameObject.transform.localPosition.y>groundHeight) { //I am still above the ground because my y value is higher than the height of the ground. Start moving downwards. //We do that the same way we started. First we find the current position Vector3 newPosition = this.gameObject.transform.localPosition; //Now we subtract our movement speed multiplied by the change in time from the last update frame. This makes sure we move at a constant rate regardless of the framerate newPosition.y-=(speedToDropAt*Time.deltaTime); //Before we move we need to make sure we didn't reach of pass the ground. if(newPosition.y<=groundHeight) { //this gets triggered if we DID pass or reach the ground. We need to just go to the ground height and stop moving newPosition.y = groundHeight; go=false; } //Lastly we actually move to the new position this.gameObject.transform.localPosition = newPosition; } } }

Viewing all articles
Browse latest Browse all 62

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>