• 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
2
Question by CoalCzar · Nov 12, 2013 at 02:42 AM · projectileendless runnerinertia

Faking inertia with projectiles in endless scroller.

I have a kind of endless scroller where the player and the camera are continually moving along the world z-axis. The player throws projectiles where the player clicks the mouse (based on a raycast from the camera). The projectile will move toward the clicked destination just fine, but it will appear faster if it is thrown behind the player character and slower if thrown in front of the player character (because of the constant motion).

To fix this, I added the constant motion of the z-axis, but now the projectile obviously misses the target location. I know there is a simple solution to getting the speed correct and the accuracy right, but I am completely blanking right now. Help?

Thanks.

Comment
Add comment · Show 3
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
avatar image Lovelock · Nov 12, 2013 at 02:49 AM 0
Share

Would having the projectile attached as a child to the player or camera help? It would allow more of a local speed ins$$anonymous$$d of global.

avatar image CoalCzar · Nov 12, 2013 at 02:59 AM 0
Share

It effectively does the same thing that my "fix" code did. Now it has the movement of the player or camera as well (which is the scrolling movement).

avatar image xt-xylophone · Nov 12, 2013 at 04:05 AM 0
Share

Im not sure if its relevant in your game but if it's childed, if the player moves backwards then so will the projectiles.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by xt-xylophone · Nov 12, 2013 at 03:59 AM

With the addition of the momentum in the z-axis you have pretty much re created how throwing projectiles works in real life.

So if you want players to still hit their mark you will either need to make them aware of the fact that aiming requires a bit more thinking i.e. aiming straight down to hit something down and right etc.

Or instead of the projectile go towards where they click, make it move to a point in front of the click point. How far in front will be some maths on how far away the target is and how fast the projectile is. This will always hit that position as it moves away from you but it 'may' look weird as the projectile leaves the player.

Or alternatively even make the projectile curve and home in on the point clicked if that satisfies how the game works.

So tldr

  • Tell the player to account for the inertia

  • Do some aim correction for them

  • Change how projectiles work

Comment
Add comment · Show 3 · 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
avatar image CoalCzar · Nov 12, 2013 at 04:55 AM 0
Share

I guess I'm looking for the "Do some aim correction for them" answer.

I have gone about this two ways now:

1) updating the direction in my update function (works, but seems wasteful)

2) The following code to create a new target point:

 distance = Vector3.Distance(target, myTransform.position);
 zOffset = (distance / (moveSpeed * Time.fixedDeltaTime)) * (scrollSpeed * Time.fixedDeltaTime);             // Take the distance between the origin and the target and divide it by the speed it will go to find how long it will take.  Take that time and multiply it by the speed of the scrolling to see how far forward on the z-axis we will go.
 target.z -= zOffset;

This code doesn't work and I'm not sure why... It ends up behind the target ins$$anonymous$$d of in front of it.

avatar image xt-xylophone · Nov 12, 2013 at 05:47 AM 0
Share

Im not sure if that will hit 100% of the time but if its just on the wrong side try changing that -= zOffset to +=?

avatar image CoalCzar · Nov 12, 2013 at 02:02 PM 0
Share
  • puts it in front of the target.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

18 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

Related Questions

How to make a projectile in the finger/mouse position in a 2D endless runner? 0 Answers

Projectile Trajectory Velocity, with predefined Start and End Positions 0 Answers

Projectile collides, freezes, but flips to weird angle. Help! 0 Answers

How to predict where the ball will fall? 4 Answers

Prediction of Path For a cannon launching a gameobject 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