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 KotaWayne · Sep 27, 2016 at 12:42 AM · rotationrigidbody2dvelocity

How do I make a 2D spaceship rotate to my mouse?

Hi I've been making a new game and I cant figure out how to give the player's ship gravity to slow down when coming to a stop. I also need help making it rotate to where the mouse is when i hold down the "W" Key. If anyone cant help I would be very happy to hear how to finished my character script :)

     public int MaxHealth;
     public float CurrentHealth;
     public Scrollbar HealthBar;
 
     public float MaxBoost;
     public float CurrentBoost;
     public Scrollbar BoostBar;
 
 
     public Sprite WeaponT1Image;
     public Sprite WeaponT2Image;
     public Sprite WeaponT3Image;
 
     public string[] WeaponTypeSelected = {"WeaponType1", "WeaponType2", "WeaponType3"};
     public int WeaponTypeNum;
 
     public Image WeaponImage;
 
     public KeyCode SwitchWeaponUp;
     public KeyCode SwitchWeaponDown;
 
     public float Speed;
     public float FireSpeed;
 
     public Vector3 targetPosition;
     public bool Moving;
 
     private Rigidbody2D Rb2D;
 
     void Start () {
         Rb2D = GetComponent<Rigidbody2D> ();
     }
 
     void Update () {
         BoostBar.size = CurrentBoost / MaxBoost;
         HealthBar.size = CurrentHealth / MaxHealth;
         //Player Movement
         targetPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
 
         if(Input.GetKeyDown(KeyCode.W)){
             Moving = true;
         } else if (Input.GetKeyUp(KeyCode.W)) {
             Moving = false;
         }
 
         if (Moving == true) {
             transform.position = Vector3.MoveTowards (transform.position, targetPosition, Time.deltaTime * Speed);
         }
         //Switch Weapons
         if (Input.GetKeyDown (SwitchWeaponUp) && WeaponTypeNum != WeaponTypeSelected.Length) {
             if (WeaponTypeNum != WeaponTypeSelected.Length) {
                 WeaponTypeNum += 1;
                 WeaponImageSprite ();
             }
         } else if (Input.GetKeyDown (SwitchWeaponDown)) {
             if (WeaponTypeNum != 1) {
                 WeaponTypeNum -= 1;
                 WeaponImageSprite ();
             }
         }
     }
 
     void WeaponImageSprite () {
         if (WeaponTypeNum == 1) {
             WeaponImage.sprite = WeaponT1Image;
             WeaponImage.rectTransform.sizeDelta = new Vector2 (10, 35);
         } else if (WeaponTypeNum == 2) {
             WeaponImage.sprite = WeaponT2Image;
             WeaponImage.rectTransform.sizeDelta = new Vector2 (30, 35);
         } else if (WeaponTypeNum == 3) {
             WeaponImage.sprite = WeaponT3Image;
             WeaponImage.rectTransform.sizeDelta = new Vector2(40, 35);
         }
     }
 }
Comment
Add comment
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

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

83 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

Related Questions

Inconsistent Velocity? 0 Answers

Rotate Rigidbody2D by Touch 1 Answer

Why is a gameobject moves at start? 0 Answers

Rotating, moving and keep on going with constant velocity in direction of click 1 Answer

Z axis not tracking 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