Quantcast
Channel: Questions in topic: "physics 2d"
Viewing all articles
Browse latest Browse all 132

Frictionless space

$
0
0
Hey I'm making a 2D space shooter, I have my player moving friction-less like I want and collisions with asteroids work, but when the player collides with an explosion the player slows down which is not what I want, the explosion is a circle that expands as the circle expands it pushes the player away, but when the explosion is destroyed the player no longer being pushed slows down, I want the player to keep it's velocity, but when the explosion is expanding and pushing the player the player's velocity does not seem to increase. I am using a physics material that is friction-less and I have tried using add force in OnCollisionEnter and Exit, but it does not seem to work right, I hope someone has a good answer here is my explosion code: public class Explosion : MonoBehaviour { CircleCollider2D cc; void Start() { cc = GetComponent(); } void Update() { if (GameManager.gameState != GameManager.GameStates.play) return; //increase the collider cc.radius += Time.deltaTime/2; //destroy object after 1.5 seconds Destroy(gameObject, 1.5f); } } Update: Sorry I didn't post my player code because there is nothing in it that slows down the player, also it happens with the asteroids when they hit the explosion as well, the increasing size of the collider is not causing the problem I just tried it with a fixed sized circle, the player and asteroid collisions work fine, it seems as the explosion collider expands it pushes the other objects away but does not effect other object's velocity for some reason.. Update 2: Here is the code I spawn the explosion with: public class LaserBeam : MonoBehaviour { float speed = GameManager.LIGHT_SPEED; public Explosion explosion; void Start() { this.GetComponent().AddForce(transform.up * speed); } void Update() { if (GameManager.gameState != GameManager.GameStates.play) return; //destroy object after 1 second Destroy(gameObject, 1); } void OnCollisionEnter2D(Collision2D col) { if (GameManager.gameState != GameManager.GameStates.play) return; //destroy target if (col.gameObject.tag == "Asteroid") //if (col.gameObject.tag != "Player") { Vector2 size = col.transform.localScale*4; Destroy(col.gameObject); //create explosion explosion = Instantiate(explosion); explosion.transform.position = col.transform.position; explosion.transform.localScale = size; //destroy object Destroy(gameObject); GameManager.playerScore += 50; } } } also my objects all have a 2d physics material with 0 friction and .666 bounciness

Viewing all articles
Browse latest Browse all 132

Trending Articles



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