|
I am modifying a shooting game where instead of the bullet traveling straight up, I want it to act under gravity and move in a parabolic motion. Right now, I have the bullet moving in a straight line with a positive slope. Is there any way I can change my code for the bullet to make it behave this way? My game is in 2D and also uses the X-axis and Y-axis. Here is the bulletScipt: var bulletSpeed : int; var bulletAngle: float; var explosion : Transform; useGravity = true; function FixedUpdate () { amtToMove = bulletSpeed * Time.deltaTime; transform.Translate(Vector3.right + Vector3.up * amtToMove); if(transform.position.y >=6.7){ Destroy(gameObject); } if(transform.position.y <= -5){ Destroy(gameObject); } } function OnTriggerEnter(otherObject: Collider){ if(otherObject.gameObject.tag == "enemy"){ playerScript.playerScore += 50; otherObject.gameObject.transform.position.y = 7; otherObject.gameObject.transform.position.x = Random.Range(-6,6); var tempExplosion: Transform; tempExplosion = Instantiate(explosion, transform.position, transform.rotation); Destroy(gameObject); } } function OnGUI() { GUI.Label(Rect(10,70,200,50),"Bullet Velocity: "+ bulletSpeed); GUI.Label(Rect(10,90,200,50),"Bullet Angle: "+ bulletAngle); }
(comments are locked)
|
|
Either give the bullet GameObject a Rigidbody with gravity enabled or script your own gravity; I was able to give the bullet a Rigidbody and enable gravity and when i fire, it does act under gravity. However, I want to control the angle (which can be controlled with the motion of the mouse) at which it is fired as well in order for the trajectory to be more parabolic
May 23 '11 at 04:07 PM
thatbigguy
So what is your question? Alter the angle.
May 23 '11 at 04:09 PM
Joshua
My question is how can I alter the angle.
May 23 '11 at 04:10 PM
thatbigguy
Right but this is the script controlling the bullet, to change where you instantiate it I assume you'd have to alter something in the turret's script. Check this out: http://www.youtube.com/watch?v=TfRhQO5PcuQ. But basically you just want to alter the angle of the object that shoots.. can't make it any simpler then that..
May 23 '11 at 04:15 PM
Joshua
This is one of the most confusing exchanges I've ever read. Make a turret with a turret script. Make a bullet with a bullet script. The turret will make bullets. Simple.
May 23 '11 at 07:07 PM
flaviusxvii
(comments are locked)
|
|
I believe the iTween library has function for handling that type of animation directly, without having to delve into the math yourself. Might come in handy.
(comments are locked)
|
