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 dovedevic · Jan 12, 2014 at 10:21 PM · transformjumpdetectionautomated

Simple AI and jump

I have a little cube that I can tell where I want it to move. I click somewhere, pass that position to the cube, and have the cube move. But I want it to jump over other cubes or obstacles if there is one in the way. Here's what I have...

 void move(Vector3 pos){
         Vector3 nV = pos;
         nV.y = transform.position.y;
         //this ignores the y component so it isnt pushing into the ground
 
 
         if(Physics.Raycast (transform.position,nV,15f)){
             if(isGrounded == true){rigidbody.velocity = Vector3.up * 15;}
         } else{
             if(transform.position.x != nV.x && transform.position.z != nV.z){
                 transform.position = Vector3.MoveTowards (transform.position,nV,.3f);
             }else{HasTask = false;}
         }
     }

At the moment, this script works 1/2 the time. And when it does, it first collides straight into another cube, jumps, then continues. I want this to be a fluid movement, not all choppy and such. If there is any way that you can help, please do. Thanks in advance!

Comment
Add comment · Show 6
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 getyour411 · Jan 13, 2014 at 01:28 AM 0
Share

Look at Time.deltaTime to smooth things out a bit.

http://docs.unity3d.com/Documentation/ScriptReference/Vector3.$$anonymous$$oveTowards.html

avatar image dovedevic · Jan 13, 2014 at 02:54 AM 0
Share

I have pretty much that. Its not the "moving towards" the point thats the issue, its the jumping.

avatar image getyour411 · Jan 13, 2014 at 02:55 AM 0
Share

Well, at last in what you posted, you don't have that at all (re: time.deltaTime). Could you clarify what about the jumping is the issue?

avatar image dovedevic · Jan 13, 2014 at 03:59 AM 0
Share

yes, that is what I am asking about. It moves towardws the object fine, however, when it gets in front of an obstacle, it will either plow right through it, jump, jump to early, or just stop moving altogether. is really a 50/50 thing when it works...

avatar image superluigi · Jan 13, 2014 at 04:28 AM 0
Share

from my understanding you can't have 2 else{}. Try changing the first one to else if{}. Also nV = pos is confusing me. If I knew what that meant I get the feeling I could figure this out.

Show more comments

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

20 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

Related Questions

Dynamic jump? 1 Answer

Sound help with script 1 Answer

Creating A wall Jump 0 Answers

Simple jump code? 2 Answers

Nested Prefab Issue 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