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 FraktuRe · May 23, 2010 at 03:28 AM · collisionmovementtargets

Making a target move when hit

I have a target that when hit sends the appropriate score to the ui, but when the target gets hit I also want it to wait for a couple seconds, then move down (which would be out of sight behind a wall), wait several more seconds and then move back up to the same position. I however don't have any idea how to make it move :(

This is the code I have so far, which waits for 3 seconds when hit, but after that I'm stumped.

function OnCollisionEnter (col : Collision) {

yield WaitForSeconds(3);

}

So what I need is code to get the initial position of the object, move it a set distance(directly down), then move it back up to the initial position(directly up). Thanks for any help!

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

3 Replies

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

Answer by ThumbStorm · May 23, 2010 at 04:26 PM

Animating the position would be the easiest. First link the object to an empty gameObject, this is done because when you animate something the object will use those exact coordinates every time it plays so if you move the object or created a duplicate it will snap to those coordinates once played, but when it's linked to another object first it zeros out the x,y,z and uses the local coordinates so you can move it if you want. Select the animated object and open the animation window, then animate it moving down, then make another animation moving from down to the up position.

var animateObject : GameObject;

function OnCollisionEnter (col : Collision) {

yield WaitForSeconds(1); animateObject.animation.Play("upPOS-downPOS");

yield WaitForSeconds(3); animateObject.animation.Play("downPOS-upPOS"); }

Comment
Add comment · Show 2 · 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 FraktuRe · May 24, 2010 at 04:26 AM 0
Share

Thank you, I managed to figure it out from this, :)

avatar image ThumbStorm · May 24, 2010 at 07:41 PM 0
Share

There's another way I just heard about. I can't remember the name so just google tween and unity, it's a free add-on and works like tweening in flash.

avatar image
0

Answer by qJake · May 23, 2010 at 05:44 AM

I don't know Javascript, so this is going to be in C#, but I think it will be easy enough to understand that you can convert it.

You need to start a coroutine when it gets hit to do everything you want.

void OnCollisionEnter(Collision other) { StartCoroutine(CollisionEvents()); }

IEnumerator CollisionEvents() { // Send score here yield return new WaitForSeconds(1); // Hide here yield return new WaitForSeconds(5); // Show here }

Comment
Add comment · Show 2 · 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 FraktuRe · May 23, 2010 at 02:01 PM 0
Share

All that appears to be is a c# version of what I already have?

avatar image qJake · May 23, 2010 at 09:54 PM 0
Share

Oh... apparently you can just yield whenever the hell you want to with Javascript... something else I should add to the list of things I hate about that language. :/

avatar image
0

Answer by Mike 3 · May 23, 2010 at 06:33 PM

function OnCollisionEnter (col : Collision) {

yield WaitForSeconds(3); transform.position -= Vector3.up; yield WaitForSeconds(3); transform.position += Vector3.up;

}

moves 1m down after 3 seconds, then 1m up after 3 more seconds (added as an alternative to the good animation answer above)

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

How to stop a character from moving out of player's control? 0 Answers

Boat collides with track(plane) below it while moving forward 0 Answers

Simple moving ball script 1 Answer

Adding collision detection to movement script... 1 Answer

How to move multiple dynamic gameobjects with one moving platform which is controlled by the player 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