Quantcast
Channel: Questions in topic: "addforce"
Viewing all articles
Browse latest Browse all 1264

How to make physics like Angry Birds Space

$
0
0
I am starting a game where I need projectiles to travel around a planet just like angry birds space. I have tried a number of things, movetowards, rotatetowards etc. but have not gotten a desirable result. I also would like to know how they make the aiming line looks like its effected by gravity to. Any thought would be extremely helpful thanks. heres a link to the game http://www.vitalitygames.com/games/angry-birds-space.html P.S. I was using my code with physics constant force and they do not seem to work very well together. I know its a mess it's because I was trying a lot of different things. public class BulletGravity : MonoBehaviour { private PlanetGravity planetgravity; public Transform target; public float gravityforce; public float rotationforce; public GameObject planet; public Vector3 centerforce; public int testangle; // Use this for initialization void Start () { } void OnTriggerEnter (Collider collision){ planet = collision.gameObject; planetgravity = planet.GetComponent(); centerforce = planetgravity.center.transform.position; Debug.Log(centerforce); } void OnTriggerStay (Collider collision){ if (collision.gameObject.tag == "Planet"){ //rigidbody.AddForce(centerforce * -gravityforce); //Debug.Log(this.transform.position); //Debug.Log(" JackPot" + collision.gameObject.renderer.bounds.center); target = collision.gameObject.transform; //Quaternion rotatetowards = - target.position; float step = gravityforce * Time.deltaTime; float rotatestep = rotationforce * Time.deltaTime; transform.position = Vector3.MoveTowards(transform.position, target.position, step); //transform.rotation = Quaternion.RotateTowards(transform.rotation, rotatetowards, step); //transform.LookAt(target); transform.RotateAround(collision.transform.position, Vector3.forward, testangle * Time.deltaTime); /*Vector3 targetDir = target.position - transform.position; Vector3 newDir = Vector3.RotateTowards(transform.forward, targetDir, rotatestep, 0.0F); Debug.DrawRay(transform.position, newDir, Color.red); transform.rotation = Quaternion.LookRotation(newDir); */ //transform.LookAt(target.position); } } // Update is called once per frame void Update () { //rigidbody.AddForce(planet.transform.position * testgravity); } }

Viewing all articles
Browse latest Browse all 1264

Trending Articles



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