Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 AkagamiSoul · May 24 at 02:27 PM · unity 2dlinerenderermousepositioncurves

Create a curve with the mouse at the apex of the curve ?

(For context: 2d plateformer game with a stone(projectile) that light up everything when shooted)

Hey so it's been a long time I wanted to do this, but I can't resolve it by myself so i'am asking all of you.

I want the to have the screen positon of the mouse to define the apex of the curve that will shoot a projectile.

So i've made this but impossible for me to do what I want... any Idea ?

 public float MouseX = 0f;
 public float MouseY = 0f;

 public Transform Heropos;

 private Camera _cam;

 public LineRenderer lr;

 void Start()
 {
     _cam = Camera.main;
 }

 public void Update()
 {
     Vector2 MousePosWorld = Camera.main.ScreenToWorldPoint(Input.mousePosition); //mouse world positon
     Vector2 MousePosScreen = Input.mousePosition; //mouse positon by the leftbottom of the screen
     transform.position = new Vector2(MousePosWorld.x, MousePosWorld.y);
     MouseX = (MousePosScreen.x + (_cam.pixelWidth / 2));  //find the center of screen  
     MouseY = (MousePosScreen.y -+(_cam.pixelHeight / 2)); // same

     Vector3 position = new Vector2(Heropos.position.x, Heropos.position.y);
     Vector3 velocity = new Vector2(MouseX, MouseY);
     
     List<Vector3> path = new List<Vector3>();

     float duration = 300f;
     float timestep = Time.fixedDeltaTime;
     for (float t = 0f; t < duration; t += timestep)
     {
         velocity += Physics.gravity * timestep;
         position += velocity * timestep;
         path.Add(position);
     }
     if (Time.timeScale == 1) 
     { 
         lr.positionCount = path.Count;
         lr.SetPositions(path.ToArray());
     }
 }

i've already a projectile behavior script and I think I just need the coordinates of my mouse to create a vector2 for it's velocity. (tell me if I'm wrong but that not what I want to be help with RN)

Thanks ya (And sorry for the bad english i'm not anglophone)

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

198 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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 make bezier curve handles dynamic? 1 Answer

Unity 2D: how to fire a renderline with raycast upward? 0 Answers

Rotate and scale sprite based on mouse position 0 Answers

Bloom effect makes some weird flashes when the character moves 0 Answers

How to get a drawn line to snap into a shape? 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