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 lalo1998 · Jul 03, 2011 at 01:14 PM · aimoveto

Help making script!!

hi, I'm not very good with scripting(seems to me like I still have a lot to learn). I need to make a script that will allow a rigidbody(ball) to go back to a certain spot(in front of my player) if it is pushed by the AI or moved too far from my player. Can anybody teach me how to do this in a script or make me a script doing what I want?

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 flaviusxvii · Jul 03, 2011 at 04:37 PM 4
Share

What's with the dramatic "!!"? I haven't been here long and I've seen so many posts like this it has become extremely easy to ignore them. I have one word for you

TUTORIALS

Find them! Learn!

avatar image lalo1998 · Jul 12, 2011 at 01:05 AM 0
Share

thanks you really helped me

avatar image _Petroz · Jul 12, 2011 at 01:21 AM 0
Share

Give a meaningful title to your question and use the tags properly.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Meater6 · Jul 03, 2011 at 04:50 PM

Well, this answer will get you only the concept, no script, you will have to make it yourself. You can do it like this:

  1. Create a transform where you want your sphere to be

  2. Lerp the position of the sphere to the transform's position

NOTE: I have never tried this method before. So it might not work. There are many more ways how to do it, I just didn't show them because they are more complicated, and you said:

I'm not very good with scripting

If it doesn't work, and you have also looked at other scripts like this one, I will make a simple example script for you.

EDIT: Here's an example script to make it work. Remember, for a noobie like you, the BEST place to learn is the Unity scripting reference, http://unity3d.com/support/documentation/ScriptReference/index.html. Your example script:

 //this script is tested
 //this script will make the object it is put on move to its "target"
 
 //move to...
 var target : Transform;
 //really the speed
 var smooth : float = 10.0;
 //distance the ball can be away from the target without moving
 var radius : float = 1.0;
 
 function Update ()
 {
     //check distance
     if(Vector3.Distance(transform.position,target.position) > radius)
     {
 
         var lerp : Vector3 = Vector3.zero;
         //Lerp function, useful yes?
         lerp = Vector3.Lerp(transform.position,target.position, smooth * Time.deltaTime);
         //set position: THE most important part
         transform.position = lerp;
     }
 }

Comment
Add comment · Show 4 · 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 lalo1998 · Jul 03, 2011 at 08:50 PM 0
Share

ok thanks I'll try this method

avatar image lalo1998 · Jul 03, 2011 at 11:23 PM 0
Share

I'm not sure if I actually did what you said. but thanks. you got me on the right track!

here's my script:

var Ball : Transform;

var separationDistance = 3.0;

var returnPoint : Transform;

function Update () {

distance = Vector3.Distance(Ball.position, transform.position);

if(distance < separationDistance)

Ball.transform.Translate(returnPoint.position);

}

avatar image lalo1998 · Jul 03, 2011 at 11:30 PM 0
Share

It doesn't work

avatar image Meater6 · Jul 04, 2011 at 04:21 AM 0
Share

Well, you can't just say

Ball.transform.Translate(returnPoint.position);

and expect it to work. Translate does not work like that. :P Here, since you really seem to be having trouble, I'll post a script the makes a object move to a transform.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

iTween Help Please MoveTo not working 1 Answer

Good refernce material for logic behind ai 0 Answers

some problems with my ai 1 Answer

simple AI - Beginner question 2 Answers

Enemy AI monster problem 3 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