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 overlordyigit1 · Oct 14, 2016 at 12:50 PM · aishipboat

Salingship ai with addforce movement

Hello mates, İm working on enemy sailing ship.i wanna learn this steps but i dont know where to start ;

ship sail somewhere in the world (wandering) , in trade route or waiting somewhere

if distance between the player and enemy is close than some number, ( i can make it )

Chase the player,when close to player turn its sides to attack with cannons and make some organic movements to wait cannon reload and attack again.

im using ceto and realistic water physic.i create my player ship movement with addforce,so im trying to do enemy ai with addforce.i searched many times but i cant find pathfinding ship with buoyancy (waves shakes ship)

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 b1gry4n · Oct 14, 2016 at 01:07 PM 0
Share

Pathfinding in a sailing game can be literally nothing if youre fighting on open water. You can have local avoidance using a overlapsphere to detect anything in range. Add a force in the opposite direction. Having a an AI ship that sails anywhere in the world seems unnecessary. What happens when you add 500 of them around the map. Are you going to calculate all of them at the same time? The player doesnt even know they exist, so why do they need to be calculated? You can come up with some clever tricks to simulate them traveling the world, but actually calculating their movement when they are nowhere to be seen, perhaps never seen, is unnecessary.

Physics overlapsphere to detect the player in an area add force in the direction to the player, if the distance is below X (using Vector3.Distance) then behave how you want.

Follow along with this series of articles : https://gamedevelopment.tutsplus.com/tutorials/finite-state-machines-theory-and-implementation--gamedev-11867

youll learn how state machines and ai work at a basic level. Youll need a state machine to act as the brain of your AI so it can make decisions based on the provided information.

I followed along and have created a little system for sharks and fish that swim around a node and eat eachother if hungry. They have local avoidance (explained in the articles) with wander, hunt, attack, and flee states.

avatar image overlordyigit1 b1gry4n · Oct 14, 2016 at 07:52 PM 0
Share

Thanks for advices,yes calculating all the ship can be unnecessary but how i can move them soo,i dont understand this part: You can have local avoidance using a overlapsphere to detect anything in range. Add a force in the opposite direction.can you explain these to me?(im new to unity coding :)) im gonna create the states later.For now i just wanna make some movements that enemy follow player,turn its sides,moving around the player ship... like these photo; alt text

1vsfleet.jpg (34.5 kB)
avatar image b1gry4n overlordyigit1 · Oct 14, 2016 at 08:58 PM 0
Share

First you would need to set up the wind controls so that the ships can move. How I am doing it (I am not using the "wind" that comes with unity) is selecting a direction for the wind by having a windcontroller, a script i made, that simple turns a transform to "lookat" the wind direction I want. https://docs.unity3d.com/ScriptReference/Transform.LookAt.html

From there, each boat would have an angle check to compare its facing direction to the wind transforms facing direction. https://docs.unity3d.com/ScriptReference/Vector3.Angle.html

If the angle is right, apply force to the boat rigidbody in the transform.forward direction. The force can be scaled based off how aligned the boat is to the wind. (smaller angle = more force) https://docs.unity3d.com/ScriptReference/Rigidbody.AddForce.html

The enemy would need to do a check to see if the player is close enough. using Invoke repeating https://docs.unity3d.com/ScriptReference/$$anonymous$$onoBehaviour.InvokeRepeating.html and casting a sphere that collides with the players collider. If it finds the player, its first state would be to move towards the player. It would have a desired direction (to the player) and would attempt to steer itself towards. https://docs.unity3d.com/$$anonymous$$anual/DirectionDistanceFromOneObjectToAnother.html

using a distance check https://docs.unity3d.com/ScriptReference/Vector3.Distance.html it would deter$$anonymous$$e what to do from there. Say you wanted it to turn to the side to fire... you would first have to do another direction change and an angle check. If all requirements are met, attack.

For your enemy to know when one of its comrades has been defeated, it would need a sort of "squad leader" script to order the ships and update them on the situation.

As you can see, it isnt exactly an easy question. If you are unfamiliar with scripting, I would start by either learning how to, or using playmaker.

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

object look center when orbiting with near sides 1 Answer

Problem with a ship controller script 1 Answer

How do I make AI objects not walk on top of each other? 5 Answers

top Down 2D flight game AI 0 Answers

Is there a way to implement a ghost mode where a ghost can replay the best possible solution of a set of data? 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