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 unity_oyq4fQ2B_8I89Q · Sep 21, 2020 at 10:07 PM · vector2directions

.normalize doesn't seem to be working properly or something, idk im tired and annoyed as frick

Ok, so this is the line of code that's been making me want to bash my head into the wall so I won't wake up for a week.

 destination = transform.position + ((Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position).normalized * dashDistance);

This measily line of code should give me a point exactly dashDistance distance away from my player. However, it's not doing that.

The normalized direction vector that gets multiplied by the dash distance and then added to the player position to give the destination point should have absolutely 0 wiggle room for how far the destination point is away from the player. It should always be dashDistance. But it's not and I've been pulling my hair out as to why.

I'm also adding the script just to give the needed context.

 public class Player_Movement : MonoBehaviour
 {
     public Rigidbody2D rb2d;
     public float dashDistance = 5f;
     public float dashSpeed = 50f;
 
     public Vector2 destination;
     public Vector2 direction;
     private bool dashing;
 
 
     void Start()
     {
         rb2d = gameObject.GetComponent<Rigidbody2D>();
     }
 
     // Update is called once per frame
     void Update()
     {
         if (Input.GetAxis("Fire1") != 0)
         {
 
         }
         if (Input.GetKeyDown(KeyCode.Mouse1))
         {
             destination = transform.position + ((Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position).normalized * dashDistance);
             direction = (destination - new Vector2(transform.position.x, transform.position.z)).normalized;
             dashing = true;
         }
 
         if (dashing)
         {
             //rb2d.velocity = direction * dashSpeed;
 
             if (Vector2.Dot(direction, (destination - new Vector2(transform.position.x, transform.position.z)).normalized) < 0.6f)
             {
                 Debug.Log("gap too big");
                 rb2d.velocity = Vector2.zero;
                 dashing = false;
             }
         }
     }
 
     private void OnDrawGizmos()
     {
         Gizmos.DrawSphere(destination, 0.5f);
         //Gizmos.DrawLine(transform.position, destination);
         Gizmos.DrawRay(transform.position, direction);
         Gizmos.DrawRay(transform.position, (destination - new Vector2(transform.position.x, transform.position.z)).normalized);
     }
 }

alt text

This is the result of the gizmos and I just don't get it. The blue circle is the player, the grey circle is the destination, and the white line is the "direction to destination"

  1. WHY CAN I PLACE MY DESTINATION SO CLOSE TO MY PLAYER, IT SHOULDN'T BE WORKING LIKE THAT

  2. WHY DOES THE LINE NOT POINT TO THE DESTINATION DESPITE, at least for what I know, THE CODE TELLING IT TO DO SO

pls help, im either missing a stupid little mistake or this has to be some issue with .normalized...

fuckin-annoying-bullshit.png (45.0 kB)
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

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

Related Questions

How do I create rotation animation for a complex object and how to use checkboxes to show specific parts of the object while it is rotating? 1 Answer

returning a relative Vector? 2 Answers

Get right or left Vector2/3 out of renderer.bounds 0 Answers

Controlling the update position of a cloned Gameobject C# 1 Answer

After placing a texture2D's pixel alpha value into an int[] array, later change that value without knowing xy coordinates? 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