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 /
avatar image
0
Question by mohanrao164 · Aug 05, 2011 at 05:41 AM · aijumpcarwaypoints

How to make an AI of a car to jump if there is any obstacle

I am doing an game in which the player car can jump using the controls from keyboard. But i want the oppenent car must also jump when there is an obstacle.i have try all the ways like using waypoints .but i did not find the solution how to do it?? please help me..
thanks in advance

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 Suyuanhan · Aug 05, 2011 at 06:04 AM

You set a JUMP function ,and set a Collier on the road where you want that car jump,

and you can use OnTriggerEnter() function to execute the JUMP function

Comment
Add comment · Show 1 · 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 mohanrao164 · Aug 05, 2011 at 10:23 AM 0
Share

this is the script using i did not get the car to jump if any error tell me

using UnityEngine; using System.Collections;

public class AIjump : $$anonymous$$onoBehaviour { public float speed = 6.0F; public float jumpSpeed = 8.0F; public float gravity = 20.0F; private Vector3 moveDirection = Vector3.zero;

 // Use this for initialization
 void Start () 
 {
 
 }
 public void  OnTriggerEnter(Collider c)
 {
     print("1");
     
     if(c.gameObject.tag=="enemy")
     {
         Destroy(c.gameObject);
             print("1");
         moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
         moveDirection = transform.TransformDirection(moveDirection);
         moveDirection *= speed;
       moveDirection.y = jumpSpeed;
         
   
     moveDirection.y -= gravity * Time.deltaTime;
        }
   
 }
 
 // Update is called once per frame
 void Update ()
 {

 }

}

avatar image
0

Answer by Meltdown · Aug 05, 2011 at 11:02 AM

Suyuanhan's solution could work, although if your level is quite large with lots of obstacles, it is an unpractical solution due to all the colliders and checks you would need to create.

A better solution is to do a Physics.Raycast from the AI car to determine if an obstacle is in the way. (You can do this by tagging all your obstacles and checking if they match that tag). Then you can use the script above for the jump or simply use Rigidbody.AddForce if your AI car has a rigidbody attached.

Comment
Add comment · Show 1 · 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 mohanrao164 · Aug 08, 2011 at 04:53 AM 0
Share

i have added the raycast and the rigidbody.addforce ,but it is not working here is my code

void Update () { Vector3 fwd = transform.TransformDirection(Vector3.forward); if (Physics.Raycast(transform.position, fwd, 30)) print("There is something in front of the object!"); rigidbody.AddForce(Vector3.up * 100); //rigidbody.AddForce(0,40,0); }

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Smooth turn.... 1 Answer

Unity 5 Standard Asset Car Waypoint AI problem with accuracy 0 Answers

How To Add AI To Car/Racer? 4 Answers

Creating enemy animation in unity 3d 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