Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Powerpuncher500 · Aug 28, 2017 at 01:23 PM · projectilepointfireprojectiles

Projectiles

So, i copied a script of someone on youtube. But since he was using an earlier version of Unity i changed some things. As far as I copied his script my projectile should be flying across the screen and destroying itself when it leaves the screen so theres not a huge pile of projectiles. But instead, the projectile appears in front of the player and immediately destroys itself. 1st Problem is as i just mentioned and 2nd Problem is, that the projectiles side doesnt change, so if you look to the left the projectile still gets shot to the right since thats where the firepoint is placed (to the left of the player). The firepoint is supposed to turn when the player does but i don't know how to do that (In the video the firepoint turned for him but it doesn't for me). If I left any information out that's important to know, to fix the problem, please tell me! Script:

 {public float speed;


 // Use this for initialization
 void Start () {
     
 }
 
 // Update is called once per frame
 void Update () {
     GetComponent<Rigidbody2D>().velocity = new Vector2 (speed, GetComponent<Rigidbody2D>().velocity.y);
 }

 void OnTriggerEnter2D(Collider2D other)
 {
     Destroy (gameObject);
 }
 
 }
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ArturoSR · Aug 28, 2017 at 09:31 PM 0
Share

Where is the rest of the code?, here just can see the movement but not from where it comes out.

avatar image Powerpuncher500 ArturoSR · Sep 01, 2017 at 08:25 AM 0
Share

Yea I'm sorry i forgot to post the other script for it. Here it is:

{ public float moveSpeed; private float moveVelocity; public float jumpHeight; private Rigidbody2D rigi;

 public Transform groundCheck;
 public float groundCheckRadius;
 public Layer$$anonymous$$ask whatIsGround;
 private bool grounded;

 private bool doubleJumped;

 public Transform firePoint;
 public GameObject Projectile;

 void Start () {
     rigi= GetComponent<Rigidbody2D>();
 }

 void FixedUpdate() {
     
     grounded = Physics2D.OverlapCircle (groundCheck.position, groundCheckRadius, whatIsGround);
 }


 void Update () {

     if (grounded)
         doubleJumped = false;


     if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.Space) && grounded) 
     
     {
         //rigi.velocity = new Vector2 (rigi.velocity.x, jumpHeight);
         Jump();
     
     }
 
 
     if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.Space) && !doubleJumped && !grounded) 
     {

         //rigi.velocity = new Vector2 (rigi.velocity.x, jumpHeight);
         Jump();
         doubleJumped = true;
     }

     moveVelocity = 0f;

     if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.D)) 
     
     {
         
         //rigi.velocity = new Vector2 (moveSpeed, rigi.velocity.y);
         moveVelocity = moveSpeed;
     }
 
 
     if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.A)) 

     {

         //rigi.velocity = new Vector2 (-moveSpeed, rigi.velocity.y);
         moveVelocity = -moveSpeed;
     }

     rigi.velocity = new Vector2 (moveVelocity, rigi.velocity.y);

     if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.Return)) 
     {
         Instantiate (Projectile, firePoint.position, firePoint.rotation);
     }
     
     }



 public void Jump()
 {
     
     rigi.velocity = new Vector2 (rigi.velocity.x, jumpHeight);

 }

}

avatar image Powerpuncher500 ArturoSR · Sep 01, 2017 at 09:01 AM 0
Share

{ public float moveSpeed; private float moveVelocity; public float jumpHeight; private Rigidbody2D rigi;

 public Transform groundCheck;
 public float groundCheckRadius;
 public Layer$$anonymous$$ask whatIsGround;
 private bool grounded;

 private bool doubleJumped;

 public Transform firePoint;
 public GameObject Projectile;

 void Start () {
     rigi= GetComponent<Rigidbody2D>();
 }

 void FixedUpdate() {
     
     grounded = Physics2D.OverlapCircle (groundCheck.position, groundCheckRadius, whatIsGround);
 }


 void Update () {

     if (grounded)
         doubleJumped = false;


     if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.Space) && grounded) 
     
     {
         //rigi.velocity = new Vector2 (rigi.velocity.x, jumpHeight);
         Jump();
     
     }
 
 
     if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.Space) && !doubleJumped && !grounded) 
     {

         //rigi.velocity = new Vector2 (rigi.velocity.x, jumpHeight);
         Jump();
         doubleJumped = true;
     }

     moveVelocity = 0f;

     if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.D)) 
     
     {
         
         //rigi.velocity = new Vector2 (moveSpeed, rigi.velocity.y);
         moveVelocity = moveSpeed;
     }
 
 
     if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.A)) 

     {

         //rigi.velocity = new Vector2 (-moveSpeed, rigi.velocity.y);
         moveVelocity = -moveSpeed;
     }

     rigi.velocity = new Vector2 (moveVelocity, rigi.velocity.y);

     if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.Return)) 
     {
         Instantiate (Projectile, firePoint.position, firePoint.rotation);
     }
     
     }



 public void Jump()
 {
     
     rigi.velocity = new Vector2 (rigi.velocity.x, jumpHeight);

 }

}

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ArturoSR · Sep 02, 2017 at 02:44 AM

@Powerpuncher500 OK, I find what is the problem about the movement (it happens to me some time ago), there is two ways to move an object, the first it's using global directions (scene or global pivot X,Y,Z) and the other it's using the transform direction or rigidbody direction (object local pivot X,Y,Z).

What I'm talking about?, you are using the velocity to move your projectiles, this way you are influencing it in a global way (scene view), instead that use the Rigidbody.transform.forward (object local), this way it moves in the right direction (could be left, right, up or down on 2D say it in other words Vector.left, Vector.right, Vector.up or Vector.down), here is a simple example using the transform.forward:

 //Setting the Rigidbody Velocity to move it using the Z local axis.
 void FixedUpdate () {
     rb.velocity = transform.forward * velocity;
 }

About the instant dead, it's about the OnTriggerEnter, you don't define any filter to avoid the detection of the player collider (may be it touch it lightly), you need to set a pair of conditionals to define the action depending of which object (trigger) has been touched, something like this:

 void OnTriggerEnter (Collider other) {
    if (other.tag == "Some Tag") {
         //Here goes your action code;
     }
 
     if (other.tag == "Some other Tag") {
         //Her goes other action code;
     }
 }

Check this two things and let me know the result after modifying them, cheers.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Powerpuncher500 · Sep 02, 2017 at 07:24 PM 0
Share

$$anonymous$$oSR

Sorry but its really hard for me to understand what you mean :/ could you maybe try to explain it in a more noob way or just tell me the code you would write?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

114 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why are my instantiated projectiles not firing? 0 Answers

how I can control projectile shooting limit??? 0 Answers

Enemy projectile direction setting 1 Answer

2D Weapon Rotation Behaviour Changes on Flipping Sprite? 1 Answer

STUCK! Firing a simple sphere from below the camera at crosshair in the centre of the screen, with or without raycast. 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges