Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
4 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 /
avatar image
0
Question by TheRandomPerson6 · Mar 14 at 03:10 PM · addforce

AddForce not working on Y

Hi, so I made an enemy that should jump at player when he is near "attack" range, I used rigidbody.AddForce to do that. When I add force x and z works perfectly but when I do y it doesnt do anything.

Code: if (states == theState.attack) { if (Vector3.Distance(transform.position, player.transform.position) > 10f) { states = theState.run; agent.enabled = true; }

             transform.LookAt(new Vector3(player.transform.position.x, transform.position.y, player.transform.position.z));
                    
 agent.enabled = false;
 
 //Buggy Part
  rigi.AddForce((player.transform.position.x - (transform.position.x)), 10f, (player.transform.position.z - (transform.position.z)), ForceMode.Impulse);
             agent.enabled = true;
             StartCoroutine(noVelocity());
             states = theState.run;    
         }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by NikkF · Mar 14 at 06:22 PM

AddForce doesn't work like "moving it up by 10 on the y axis" as you wrote.

Instead, you have to specify a direction (in your case Vector3.up if you want it to always go up, or transform.up if it should consider object rotation) and multiply that by a force value.


Here's the difference between transform.up and Vector3.up: alt text


Use something like this instead:


 rigidBody.AddForce(Vector3.up * force, ForceMode.Impulse);


Hope this helps!


directions.png (19.5 kB)
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
avatar image
0

Answer by TheRandomPerson6 · Mar 14 at 06:32 PM

Hi, I tried " rigi.AddForce(transform.up * 20f, ForceMode.Impulse);" it but it doesnt seem to work. Do you got other solutions? Cheers

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 NikkF · Mar 14 at 06:50 PM 0
Share

Well, in that case, I assume your object is either static or kinematic. Make sure that the RigidBody has isKinematic set to false as this will prevent your object from doing physics.

If that also doesn't work, then I assume it's an issue with something I can't see here.

avatar image TheRandomPerson6 NikkF · Mar 15 at 06:17 PM 0
Share

Hi, so the bug got caused because of what you said and I immediatly activated navMeshAgent right after adding force.

Sorry to waste your time :(

avatar image NikkF TheRandomPerson6 · Mar 16 at 01:23 AM 0
Share

No worries man! Glad you got it sorted :)

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

134 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

Related Questions

`Inventory' does not contain a definition for `Add' 2 Answers

I need to add a force to an object based on the local vector of the object that is hitting it and not the world coordinates or local coordinates of the object being hit. 1 Answer

Facing the target 0 Answers

activate and speed in z axis from a pooled inactive object!! 1 Answer

2D character can't jump off of platform floating in water 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