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 sebastianregelmann03 · Nov 24, 2020 at 08:58 PM · 2d game2d-platformer2d sprites

Hey Guys. I am creating my first 2d Game right now an i run into a problem with sprites.

Hey Guys. I am creating my first 2d Game right now an i run into a problem with sprites. I am implementing a grappling hook and got everything run like i want. The only thing left is that i want a sprite from the player to the point on the wall. And the best would be when i could use a repetitiv sprite.

Thanks to everybody who trys to help

Sebastian

 public class GrapplingHook : MonoBehaviour {
 
 [Header("Positions and Player")]
 public LayerMask whatIsGround;
 public Transform Player;
 public float StopGrapRange = 0.5f;
 public float GrapplingRange;
 public float GrapSpeed;
 
 private Vector3 MousePosition;
 
 private RaycastHit2D hit, hitOld;
 public Ray ray, rayOld;
 
 public Rigidbody2D rb;
 private float step;
 
 private float time = 0.0f;
 private bool GrapToPoint = false;
 
 void Update()
 {    
     if(Input.GetMouseButtonDown(1) && time > 2f)
     {
        GetGrappPoint(); //Get GrappPoint
        print("hit.distance: " + hit.distance);
 
        rb.bodyType = RigidbodyType2D.Static;    //Deactivate the Rigidbody "Physics"
        time = 0f;
     }
 
     else if (Input.GetMouseButtonDown(0)) 
     {              
         GrapToPoint = false;
         rb.bodyType = RigidbodyType2D.Dynamic;  //Reactivate the Rigidbody "Physics"       
     }
     else if (hitOld.distance < StopGrapRange) 
     {              
        GrapToPoint = false;
        rb.bodyType = RigidbodyType2D.Dynamic;   //Reactivate the Rigidbody "Physics"      
     }
 
     if(GrapToPoint)
     {
     float step = GrapSpeed * Time.deltaTime;     
     Player.transform.position = Vector2.MoveTowards(transform.position, new Vector2(hit.point.x, hit.point.y), GrapSpeed * Time.deltaTime); //Move Player to the point 
     }
 
     CheckRay(); //Check if Player is still away from the Wall
 
     time = time + Time.deltaTime;
     }
 
 private void GetGrappPoint()
 {
     ray = Camera.main.ScreenPointToRay(Input.mousePosition);    //Get Mouseposition raltiv to the world
     rayOld = ray;
 
     hit = Physics2D.Raycast(ray.origin, ray.direction, GrapplingRange,  whatIsGround);  //get next wall(collider)
 
     if(hit.collider != null)
     {     
     Debug.DrawLine(Player.transform.position, new Vector3(hit.point.x, hit.point.y, 0.1f), Color.red, 100f);
     GrapToPoint = true;    
     }
 }
 
 void CheckRay() //Check if Player is still away from the Wall
 {
     hitOld = Physics2D.Raycast(transform.position, rayOld.direction, GrapplingRange, whatIsGround);
     print("RayCheckLenght" + hitOld.distance);
 }
 }
 
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

192 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

Related Questions

How to fix random lines that appear in my background. 1 Answer

Sprite turning around repeatedly against a wall. How to have "Wallslide" flip sprite? 0 Answers

Help Me! I want to make a pixel fairy! 1 Answer

How to create soil or sand?? 1 Answer

"Create New Palette" doesn't actually create a palette at all 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