Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by v3ry · Oct 28, 2011 at 12:14 AM · shooterscrollingsidescrollersidescroller

projectile to cursor for a side scrolling shooter

I have a game project due, it is my final and our time frame is 9 days; which isnt that bad considering that I have a small scope for my game. The only hang up that I have run into is getting my character which does shoot, to be able to aim up and down on the y axis as the player moves along the x. A classmate told me about usinga Plane Collider in the background , set up a Vector 3 that calculates xyz but it has all gone over my head! I am an art guy by nature, drawing, modeling work, texturing is what I am most proficient so wrapping my head around code is an arguous task for me.... This is the code in which I am currently using to fire bullets:

 var myCamera : Transform;
 var prefab : Transform;
 var player : GameObject;
 // point of origin for particles
 var flashpoint: Transform;
 // actually particles
 var muzzleFlash: GameObject;
 var otherClip : AudioClip;
 
 function Update () 
 {
         if(Input.GetButtonDown("Fire1"))
         {
             Instantiate(muzzleFlash, flashpoint.transform.position, flashpoint.transform.rotation);
             var myBullet = Instantiate(prefab, myCamera.transform.position, myCamera.transform.rotation);
             //this tells the ingine to ignore detection of coliders between bujllet and player
             Physics.IgnoreCollision(player.collider, myBullet.collider);
             myBullet.rigidbody.AddForce(myBullet.transform.forward * 5000);
             if (!audio.isPlaying)
             {
                 audio.clip = otherClip;
                 audio.Play();
             }
         }
 }

and this is some code I found that does what I want apparently, only I do not have the slightest as how to impliment it into my game or if it is c# or javascript syntax:

 // Find the difference vector pointing from the weapon to the cursor
 Vector3 diff = cursor.transform.position - weapon.transform.position;
 // Always normalize the difference vector before using Atan2 function
 diff.Normalize();
 
 // calculate the Z rotation angle using atan2   
 // Atan2 will give you an angle in radians, so you
 // must use Rad2Deg constant to convert it to degrees
 float rotZ = Mathf.Atan2(diff.y,diff.x) * Mathf.Rad2Deg;
 
 // now assign the roation using Euler angle function
 weapon.rotation = Quaternion.Euler(0f,0f,rotZ);
Comment
Add comment · Show 2
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 v3ry · Oct 27, 2011 at 10:18 PM 0
Share

would it be possible to implement the code at the bottom into my already existing code at the top???

avatar image syclamoth · Oct 28, 2011 at 12:20 AM 0
Share

Yes- Learn C#, since it'll serve you better in the future, and doesn't have the weird fuzzy syntax that Javascript suffers from.

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

camera boundary and movement in rtype style scrolling shooter 3 Answers

Scroll rect snaps everytime with drag 0 Answers

Sprite Manager Animation/Walker Brothers Mario 1 Answer

Unity is ignoring the minus 4 Answers

Trying to get character to instantly rotate in 2.5d side scroller 1 Answer


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