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
2
Question by Mike 34 · Apr 08, 2011 at 12:07 PM · animationmovementtriggerproximity

How can I animate an object to my proximity and movement?

I'm not sure the best way to explain this, but this Simpsons clip actually shows what I'm trying to achieve quite well:

http://www.youtube.com/watch?v=G5CZ58CBGtg

I am trying to animate an object in a similar way to how the sun reacts to Homer's movement. In my Unity scene, Homer would be the FPS Controller and the sun would just be a cube (to keep it simple).

I'm basically trying to make it so when you walk closer to the cube it goes up in the Y-axis (until it has reached where I want it to stop) and when you walk away it goes down. If you are not moving, neither should the object

I'm new to Unity and don't know any scripting so any starting point would be helpful

Comment
Add comment · Show 1
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 Justin Warner · Apr 08, 2011 at 12:32 PM 0
Share

Get the players X/Z axis (Depending on where the sun is), make the sun equal to the Y and X/Z axis of the sun (Again, depending on where the sun is). This could work roughly...

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Statement · Apr 08, 2011 at 01:14 PM

A simple solution would be to create a script that measure distance to the player, and lerp position for the sun. The sun could be made a child of the object, placed in 0, 0, 0 local. When you get closer in x/z, the sune rise in y. If you want to measure distance in all axes, then just remove a.y = b.y;

var player : Transform; // Target your player var sun : Transform; // Target your sun var range = 10.0f; var sunHeight = 5.0f

function Update() { var a = player.position; var b = transform.position; a.y = b.y; // Optional var distance = Vector3.Distance(a, b); var percent = Mathf.Clamp01(distance / range); sun.localPosition = Vector3.Lerp(Vector3.up * sunHeight, Vector3.zero, percent); }

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 Mike 34 · Apr 09, 2011 at 01:14 PM 0
Share

Thanks for the quick reply! Will give this a go soon and let you know how I get on

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

Having a door dissapear once a key is collected 1 Answer

Help with setting up a trigger animation 1 Answer

Script on moving object doesn't work? 1 Answer

Animation not playing but trigger works 1 Answer

Interrupt a MoveTowards when triggering 2 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