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 thendricks · Aug 22, 2012 at 04:15 PM · aitanks

Please help me with AI

Im creating a 3rd person sci-fi tank game an I need an AI script without animation as the tanks float.

Raycast or waypoint would be alright (never used these methods)

thanks in advanced.

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 Cool Dave · Aug 22, 2012 at 04:32 PM

Here's my code from a car AI I made. With a little adjustment for tank steering, it should work fine. Actually, you could simplify it a lot for a tank. Hope it works!

`//var target : Transform;

var waypoints : Transform[];

var frontLeftColl : Collider;

var frontRightColl : Collider;

var rearLeftColl : Collider;

var rearRightColl : Collider;

var armLeft : Transform;

var armRight : Transform;

var frontLeft : Transform;

var frontRight : Transform;

var rearLeft : Transform;

var rearRight : Transform;

var carCenter : Transform;

var steering = 0.00;

var graphicSteering = 0.00;

var angleDisplay = 0.00;

var engineTorque = 0.00;

var carAngle = 0.00;

var maxSpeed = 0.00;

var xDistance = 0.00;

var zDistance = 0.00;

var loop : boolean = false;

var targetWaypoint : int;

var waypointRadius = 0.00;

var angularDistance = 0.00;

function FixedUpdate () {

wheelRpm = frontLeftColl.rpm;

//Waypoint System target = waypoints[targetWaypoint];

xDistance = target.position.x - carCenter.position.x; zDistance = target.position.z - carCenter.position.z;

angularDistance = (Mathf.Sqrt(xDistance xDistance) + (zDistance zDistance));

if (angularDistance < waypointRadius){ targetWaypoint += 1; } if (loop == true){ if(targetWaypoint >= waypoints.Length){ targetWaypoint = 0; } } //targetwaypoint is a number.

//var targetDir = target.position - frontLeft.position;
//var forward = frontLeft.forward;
//var angle = Vector3.Angle(targetDir, forward);
/* carCenter.LookAt(target);

armRight.rotation = Quaternion.Slerp (armLeft.rotation, carCenter.rotation, Time.time 1); armLeft.rotation = Quaternion.Slerp (armLeft.rotation, carCenter.rotation, Time.time 1); frontLeftColl.steerAngle = carCenter.rotation.y; frontRightColl.steerAngle = carCenter.rotation.y; //steering = Quaternion.EulerRotation(target); //steering = blahBlah.rotation.y; //armRight.LookAt(steering);

*/

var angle : float = Mathf.Atan2(xDistance, zDistance) * Mathf.Rad2Deg;

carAngle = carCenter.eulerAngles.y; steering = (angle - carAngle); angleDisplay = angle;

frontLeftColl.steerAngle = steering; frontRightColl.steerAngle = steering;

graphicSteering = steering;

if (graphicSteering > 360){ graphicSteering -= 360; } if (graphicSteering < 0){ graphicSteering += 360; }

if (graphicSteering > 45){ if (graphicSteering < 315){ graphicSteering = 45; }} if (graphicSteering < 315){ if (graphicSteering > 45){ graphicSteering = 315; }}

armLeft.localEulerAngles.y = (graphicSteering); armRight.localEulerAngles.y = (graphicSteering);

if (frontLeftColl.rpm > maxSpeed){ finalTorque = 0; } if (frontLeftColl.rpm < maxSpeed){ finalTorque = engineTorque; }

frontLeftColl.motorTorque = finalTorque; frontRightColl.motorTorque = finalTorque;

frontLeft.Rotate(Vector3.right wheelRpm ( 360/60 ) Time.deltaTime); frontRight.Rotate(Vector3.right wheelRpm ( 360/60 ) Time.deltaTime); rearLeft.Rotate(Vector3.right wheelRpm ( 360/60 ) Time.deltaTime); rearRight.Rotate(Vector3.right wheelRpm ( 360/60 ) Time.deltaTime);

}`

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 Sundar · Aug 22, 2012 at 04:37 PM

Check this ETeeskiTutorials

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

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

9 People are following this question.

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

Related Questions

AI tank keeps running into trees adn getting stuck?,AI tank running into trees 0 Answers

is their a way to make an AI using Wheel Collider and the Navmesh agent ? 0 Answers

Tennis game like Grand slam tennis 1 Answer

How do I stop an Enemy NavMeshAgent from intersecting the player model? 3 Answers

How to allow multiple nav mesh agents with different slope climbing abilities to use the same nav mesh? 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