Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 Sheketchecka · Jul 05, 2015 at 04:48 AM · c#2draycastplatformerinfinite

Upon shooting, Raycast target moves infinitely

Hello, I'm working on a Metroidvania style platformer and can't seem to figure out getting the shooting aspect to work properly.

I'm using a Raycast to launch forward upon shooting to check if I can hit something, but the object that I'm using as the direction to shoot in (which I've called the endpoint) moves in various speeds in a set direction along the X axis when I point it either way. When I'm moving it is in the correct position, but sometimes it doesn't move to point in the opposite direction, other times it automatically moves to the other side when I don't want it to and others it just disappears.

When shooting the Raycast line does hit and end at the objects that I want it to, but I don't think I should leave the endpoint moving forward forever.

         Vector2 input = new Vector2 (Input.GetAxisRaw ("Horizontal"), Input.GetAxisRaw ("Vertical"));
         Vector2 endPosition = new Vector2(endPoint.position.x, endPoint.position.y);
 
 
         if (input.y == 0 && input.x == 0) {
             endPoint.transform.localPosition = new Vector2 (endPosition.x, 0);
         }
         if (input.y > 0.25) {
             endPoint.transform.localPosition = new Vector2 (0, 1);
         }
         if (input.x > 0.25) {
             endPoint.transform.localPosition = new Vector2 (2, 0);
         }
         if (input.x < -0.25) {
             endPoint.transform.localPosition = new Vector2 (-2, 0);
         }


https://youtu.be/qihWSGiCypc Link to demonstration if I'm not explaining it correctly.

I of course want to just leave the endpoint's X axis position at 2 or -2 from the center of my character based on what I had it at last. Pointing upward seems to work fine, where the endpoint moves to where I want it to when pushing up. But it's the horizontal pointing which is all messed up. Any ideas? Please forgive me if this is a simple fix, this is my first time programming a game.

Thanks in advance!

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
0

Answer by Sheketchecka · Jul 06, 2015 at 03:05 AM

Well I'm not too sure what I did but I ended up fixing it. I think I maybe when I had it shooting forever I also had it set to move while shooting. Either way, I have shooting working now. Case closed!

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

2 People are following this question.

avatar image avatar image

Related Questions

2D platformer- getting errors I don't understand (c#) 1 Answer

How to make a simple line of sight in a 2D top down shooter. 3 Answers

Load Scene Moving Too Fast(C#) 1 Answer

Simple collision detection C# 2D 1 Answer

2D Flashlight for a platformer 2 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