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 janjoeljanjoel · Aug 09, 2020 at 06:28 AM · scripting problembeginner

a way to predict players position to be able to be hit by projectiles

hi, I'm making a Boss AI that I need is a way the Boss AI to trow projectile and predict its future position base on the speed of the player. the player either on land or air vehicle. the projectile has a constant speed, a rigidbody, and can easily be seen by the player want I want is that the player has a chance to dodge the projectile. don't worry about the speed constant I already have that one just the prediction is what I need.

this is the player controls just in case you need it

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class SpeedupSkill : MonoBehaviour { protected SpeedButton SpeedButton; //looking for script leftbutton public float cooldownTime = 7; private float nextFireTime = 0; private double nextFireTime2 =0; private double nextFireTime3 = 0; public double cooldownTimeleft = 0.2; public double cooldownTimeright = 0.2; public float maxSpeed = 100f; protected Leftbutton LeftButton; //looking for script left buttton protected Rigthbutton RigthButton; //looking for script right button

 public int damage = 50;






 // Use this for initialization
 void Start()
 {

     SpeedButton = FindObjectOfType<SpeedButton>();
     LeftButton = FindObjectOfType<Leftbutton>();
     RigthButton = FindObjectOfType<Rigthbutton>();
    




}

 // Update is called once per frame
 void Update()
 {
     var rigidbody = GetComponent<Rigidbody>();


     
    
     if (SpeedButton.Pressed && Time.time > nextFireTime)

     {

        

         rigidbody.velocity += Vector3.forward * 100f;
         nextFireTime = Time.time + cooldownTime;
         GetComponent<Renderer>().material.color = Color.red;




     }
     if (LeftButton.Pressed && Time.time > nextFireTime2)
     {
         rigidbody.velocity += Vector3.right*1.0f ;
         nextFireTime2 = Time.time + cooldownTimeleft;
         Quaternion.LookRotation(Vector3.forward);
     }
     if (RigthButton.Pressed && Time.time >nextFireTime3)
     {
         rigidbody.velocity += Vector3.left*1.0f;
         
         nextFireTime3 = Time.time + cooldownTimeright;
         Quaternion.LookRotation(Vector3.forward);
     }
     if (rigidbody.velocity.magnitude < maxSpeed)
     rigidbody.velocity += Vector3.forward*30.0f;
     else
         rigidbody.velocity += Vector3.forward * 0.0f;
     if (rigidbody.velocity.magnitude < 29.9f) 
     rigidbody.velocity += Vector3.forward * 1.0f;
  


 var grounded = Physics.Raycast(transform.position + Vector3.up * 0.05f, Vector3.down, 2f);
     Debug.DrawRay(transform.position + Vector3.up * 0.05f, Vector3.down, Color.red, 0.1f);
     if (!grounded)

         rigidbody.velocity -= Vector3.down * -2.0f;




 }

 

}

edit: the game is 3d

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

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

249 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 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

Is what a parent gameobject can consult or modify components attributes of it desactivated gameobject children 0 Answers

How to use a timer with a button 2 Answers

True and false work weird? 1 Answer

OnTriggerEnter and UI Collisions. 0 Answers

Instantiate not working? 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