Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by AakashH94 · Nov 23, 2015 at 08:17 PM · 2dphysicsaiobstacle avoidancethrowing

How to get AI to throw object over obstacles

alt text

What I am trying to do is to get the the AI to throw a grenade over an obstacle to its target. What I have so far is just having the AI throw a grenade at the target which works fine but I have no idea how to get it to think about the obstacles that are in the way like in the picture shown below. I want A to notice there is a wall in the middle and throw the object over it to be.

 Vector2 diff = target.position - this.character.transform.position;
         Vector2 grenadeVel = new Vector2();
         grenadeVel.x = diff.x / grendadeDetonationTime ;
         grenadeVel.y = (diff.y - 0.5f * worldGravity.y * grendadeDetonationTime *   grendadeDetonationTime ) / grendadeDetonationTime ;
 
         Debug.Log(grenadeVel);
         World.Instance.WeaponManager.Grenade.Throw(this.character, grenadeVel);


Im not really asking for code (although it would be great), what I want is some advice/ tips on how to implement this and what the logic might be like. Currently my game world is in 2D and it has a grid which I use for path finding with the A* algorithm, is it possible to do what I want using a world grid to create an arch over obstacles?

ai.png (9.7 kB)
Comment
Add comment · Show 2
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 ZefanS · Nov 24, 2015 at 09:12 AM 0
Share

You may be able to use a Raycast to detect obstacles in front of the AI, and then have it react differently, ie. throw the grenade higher.

avatar image Guppie1337 · Nov 24, 2015 at 03:06 PM 0
Share

Raycast to find objects in the path. If height of objects are a concern, you could detect how tall it is before changing the trajectory. In a situation where you would face a wall or a building, this would be a good idea. You can usually throw over a wall, but can't throw over some tall buildings. This could cue another part of the AI to move to a position where it is reasonable to carry out the action.

An easy way to do it is just hardcode in trajectories if it is flat land same height walls. This gets all wonky once you start changing relative elevation to obstacles though. i.e standing lower than a wall that is on top of a hill.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by suark · Nov 25, 2015 at 09:18 AM

As ZefanS said, First make a raycast from ai player to target area. if raycast hits and object, change the angle (http://docs.unity3d.com/ScriptReference/Quaternion.AngleAxis.html) of the raycast till it doesn't hit anything. Thats the point AI should throw the ball over.

Comment
Add comment · Show 2 · 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 AakashH94 · Nov 26, 2015 at 04:20 PM 0
Share

Thanks! That is really useful to know :D one other thing, would you happen to know of an algorithm that I would be able to use to throw the object over the obstacle with the right amount of Velocity to get to the target with the angle data I receive from Raycasting?

avatar image suark AakashH94 · Nov 27, 2015 at 09:53 AM 0
Share

If you are using physics try this https://en.wikipedia.org/wiki/Trajectory_of_a_projectile.

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Changing gravity depending on character/camera rotation 0 Answers

Player Movement Not Always Responding 1 Answer

Collider fires consistently, but Trigger does not? 0 Answers

Addforce for 2d game is not doing anything. 0 Answers

2D Platform irregular jump 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