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
1
Question by dkreigns · Nov 11, 2014 at 10:53 PM · animationprefabs

Scripting BUG: target becomes bigger when getting nearer

I try to brief on this one because I was kinda this problem for a little while :< I have a zombie prefab (animations included), 2 scripts - Look.JS and Chase.JS, and a First-Person Character controller. Here's my code for the script:

Look.JS:

 var target : Transform;
 
 function Update() {
     transform.LookAt(target);
 }

And Chase.JS:

 var target : Transform;
 var speed : int;
 
 function Update() {
     animation.Play('walk');
     transform.position = Vector3.MoveTowards(transform.position, target.position, Time.deltaTime * speed);
 }

The script works and the zombie followed me while playing the 'walk' animation. But there's seems to be some sort of code error or something that whenever the zombie gets nearer to me, he became more bigger and bigger o.O Except from that the code works perfect. Can you help me how to fix this? I need this for my school project and deadline is 2 days from now and I'm kinda stuck here :( Thank you! :)

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 AlwaysSunny · Nov 11, 2014 at 05:48 PM 0
Share

Nothing you posted will affect the size of anything. The model will appear to get bigger as it approaches your perspective camera. If there is nothing to stop it from doing so, such as a collider or a coded response to proximity, it will attempt to occupy the same position as the target, which may account for "getting bigger and bigger".

avatar image dkreigns · Nov 11, 2014 at 08:48 PM 0
Share

How can I fix this :?

avatar image AlwaysSunny · Nov 11, 2014 at 10:33 PM 0
Share

If you believe this is what's happening - that the object simply gets too close to the camera - you have several options.

You might simply avoid seeking if within a certain distance:

 Vector3 difference = target.position - transform.position;
 float magnitude = difference.magnitude;
 if (magnitude > 0.5f) {
 animation.Play('walk');
 transform.position = Vector3.$$anonymous$$oveTowards(transform.position, target.position, Time.deltaTime * speed);
 }
avatar image robertbu · Nov 11, 2014 at 11:45 PM 0
Share

One thing to try would be to reduce the field of view and then pull the camera back. This doesn't fix the problem, but it might reduce the distortion associated with having an object close. Or if you really don't want things to get bigger, change your camera to orthographic.

avatar image Habitablaba · Nov 13, 2014 at 11:02 PM 3
Share

This isn't a bug, its just how things work. This goes for real life, too.
Put your hand out at arms length, then move it towards your face. See how it takes up more of your view, the closer it gets?
Science.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Baste · Nov 12, 2014 at 12:06 AM

If it's actually a perspective thing where the thing appears larger because you're closer to it, just set your camera to orthographic instead of perspective.

Grab your main camera object in the scene, select the Projection drop-down, and select 'Ortographic'.

Comment
Add comment · Show 5 · 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 dkreigns · Nov 12, 2014 at 02:05 PM 0
Share

Still now working bro :<

avatar image AlwaysSunny · Nov 12, 2014 at 02:44 PM 0
Share

Please post a video or screenshot showcasing the issue so we can understand. Your description isn't reinforced by enough Unity knowledge and jargon to be informative.

avatar image dkreigns · Nov 12, 2014 at 10:27 PM 0
Share

Ok I'll do that man

avatar image dkreigns · Nov 14, 2014 at 11:39 AM 0
Share

Here's the video of it https://www.youtube.com/watch?v=E6UiJX66noI

avatar image AlwaysSunny · Nov 14, 2014 at 11:41 AM 1
Share

I do not see the model getting bigger in this video. I see the model getting closer to the camera. It thus appears bigger. As eloquently stated by @Habitablaba,

"Put your hand out at arms length, then move it towards your face. See how it takes up more of your view, the closer it gets? Science."

avatar image
0

Answer by dkreigns · Nov 14, 2014 at 12:56 PM

Ok I'll post another vid. I'll create a 2 of them now,, trust me he's really getting bigger -_- I'm not stupid

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Can the animation editor create local rotational data? 3 Answers

How to shoot prefab, and then on colliding destroy a gameobject? 2 Answers

A simple animation clip scripting control example... DOES NOT EXIST! - loosing clumps of hair on this one 1 Answer

Possible to play single clips using Mecanim? 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