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 BruceT · Jun 18, 2013 at 03:19 AM · distanceforceinverse

Force of bullet - Distance to Object

Hi guys,

I have searched for this but I can't find it mentioned (though that could be because I am searching for the wrong thing)

I am trying to set the force of a bullet depending on the distance to the player. I need to work in reverse though of course so that the bigger the distance the less force is applied.

I found mention of the inverse of this which is something like this...

force = 1 / distanceToPlayer distanceToPlayer bulletForce;

This just gives me the initial bullet force though.

Not being a math's genius I was hoping to ask is there a way to inverse the distance?

I hope I have explained this well enough!

Thanks for your time.

Sincerely,

Bruce

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
Best Answer

Answer by robertbu · Jun 18, 2013 at 04:01 AM

I'm not sure what you are looking for here. If you are letting the physics engine do the work, how much force will be applied with depend on the momentum of the bullet. So one easy way to solve this problem would be to setup some drag for the projectile in the Rigidbody component. The further it travels, the slower it goes.

If for visual reasons you did not want to slow the projectile, you could (in theory since I've never tried it), scale the mass over time. For a non-linear decline you can do something like each frame or each FixedUpdate():

 rigidbody.mass = rigidbody.mass * 0.998;

Here is the calculation I think you are asking for:

 if (distanceToPlayer < maxDist)
     force = (maxDist - distanceToPlayer) / maxDist * forceFactor;
 else
     force = 0.0;

Where max distance is the maximum effective distance of the projectile. This gives a linear dropoff.

Comment
Add comment · Show 1 · 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 BruceT · Jun 18, 2013 at 04:10 AM 0
Share

$$anonymous$$any thanks Robert!

There is no actual bullet, it is done with ray casting and parameters (such as force and distance) are set via the weapon script. Sorry, I should have explained that at first.

So the second part of your response is perfect!

Thanks again :)

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

14 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

Related Questions

Rotational Force 0 Answers

How to get inverse Force? 2 Answers

calculate the estimated distance travel based on the Force applied to Rigid Body 1 Answer

How to disable the physical reaction of a distance joint 2D? 1 Answer

Gravity within range 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