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 /
avatar image
0
Question by Scruffman10 · Apr 07, 2020 at 08:06 PM · anglesangle adjust

Finding the x and y of Mathf.Atan2 after converted to degrees

Hello I'm trying to figure out how solve the x and y of Math.Atan2 after it is calculated and converted into a Degree using Mathf.Rad2Deg since I want to add a small change in the angle like 15 degrees or so which can be changable. I am mainly trying to implement this so I can have a 2d platformer directional shooter that shoots multiple bullets at once for my enemies to add more difficulty to the game

  using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
 
 public float y;
 public float x;
  public class PointAndShoot : MonoBehaviour
  {
 void FixedUpdate() {
     float rotationZ = Mathf.Atan2(y, x) * Mathf.Rad2Deg; 
                 
 //Want to figure out if its possible to add or subtract degrees from rotationZ and figure out what the
 //x and y are in that degree angle
        }
     }








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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Namey5 · Apr 08, 2020 at 04:16 AM

You can figure out where the new point [x,y] would be through trig identities;

 //Calculate angle theta
 float theta = Mathf.Atan2(y, x) * Mathf.Rad2Deg;
 
 //Make whatever change you want to the angle, in this case subtract 10 degrees
 theta -= 10f;
 
 //Let's say we have an angle 'a', which we get from 'a = atan2 (y, x)'
 //'atan' is the inverse of 'tan', therefore 'atan (tan (a)) = a'
 //We also know that 'tan (a) = sin (a) / cos (a)'
 //Therefore 'atan (sin (a) / cos (a)) = a'
 //You'll notice that 'Vector2 (cos (a), sin (a))' is a point on the circumference of a unit circle rotated 'a' degrees
 //This is actually the basis of how 'atan2' is calculated in the first place, i.e. 'atan2 (y, x) ~ atan (y / x)' (not strictly correct, but close enough for this example)
 //Therefore, for a point/vector at 'theta' degrees; x = cos (theta), y = sin (theta)
 float newX = Mathf.Cos (theta * Mathf.DegToRad);
 float newY = Mathf.Sin (theta * Mathf.DegToRad);


You can read more about atan2 here;

https://en.wikipedia.org/wiki/Atan2

Comment
Add comment · 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

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

124 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

how can i determine the angle of the face of an object relative to the world? 0 Answers

user input azimuth and elevation angle. Need Urgent Help 0 Answers

Shade Based on Normal Map World Position Angle (Updated) 1 Answer

Align line of units based on vectors 0 Answers

Clamp Rotation of an object depending of the Rotation of an other one 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