Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Panamamigo · Jul 24, 2010 at 09:29 PM · collisionmovementfreezestopwander

freeze an object for a while or reset value or reverse it?

Basically I have a red sphere that chases around green spheres. The green spheres wander around by themselves by going from randomly generated way point to randomly generated way point. Everything is working great, however no matter what I do I cannot make them continue running around after they collide with something. Instead the rigidbody spheres break their movement and fly in one direction until they hit a wall. I want to be able to send my green spheres in the opposite directions after a collision (so if their heading to (2, 1, 3) now they'd go to (-2, 1, -3) or have then choose a new way point or something. I'll post up my script any help would be appreciated. The script below just manages health and the wandering.I tried reusing the Wander function that you will see in the script for the collisions but it makes them extremely jittery and they just spaz out.

var health : int= 30; var dead : boolean= false; var DeadSpeed : float= 0.5; var Speed= 10; var wayPoint : Vector3;

function Start() { Wander(); }

function OnCollisionEnter(collision : Collision) { if(!dead && collision.gameObject.tag=="P Bullet") { health -= 10; Debug.Log(health); if ( health <= 0) { dead = true; } }

 if(collision.gameObject)
 {
     //Make the object stop? Go in the opposite direction? or choose a new waypoint???
 }

 if(collision.gameObject.tag=="Player")
 {
     //Make the object stop? Go in the opposite direction? or choose a new waypoint???
 }

}

function Update() { var dist : float =(Appear.ActivePos - transform.position).sqrMagnitude; transform.position += transform.TransformDirection(Vector3.forward)*Speed*Time.deltaTime;

 if((transform.position - wayPoint).magnitude &lt; 3 &amp;&amp; dead != true)
     {
         Wander();
     }

 if(dead)
 {

     if(dist &gt;= 2)
     {
         transform.LookAt(Appear.ActivePos);
         transform.Translate(Vector3.forward * DeadSpeed, Space.Self);
     }
     else
     {
         transform.position=Appear.ActivePos;
         Destroy (gameObject);
         Appear.ActiveObj.active= true;
         Appear.visible.Add(Appear.ActiveObj);
     }
 }

}

function Wander() { wayPoint= Random.insideUnitSphere *120; wayPoint.y = 1; transform.LookAt(wayPoint); }

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
Best Answer

Answer by Panamamigo · Jul 25, 2010 at 06:53 PM

After working on this problem for hours more I have discovered the problem. Some of the spheres would collide with the ground and since that was a collision with a gameObject it would keep changing waypoints. I fixed it using tags and now it works fine.

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 slayer.du · Dec 20, 2010 at 10:33 AM

nice solution that's what am looking for thx dude

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

No one has followed this question yet.

Related Questions

Object going through another....How to solve it? 0 Answers

How to prevent movement in a specific direction only? -1 Answers

Simple movement problem. Need units to stop dead on collision. 3 Answers

Mouse Look Freeze on Pause? 1 Answer

Unreliability of Physics.Raycast.Distance for player movement? 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