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 Alan Fletcher · Feb 23, 2013 at 10:03 PM · c#

Mathf.pingpong

when i use mathf.pingpong it move my object in both directions however i want it to start at 0 and go to 'n', as it stands instead of moving in both directions. My object is a simple cube object.

here is the code i am using to do this

using UnityEngine; using System.Collections;

 public class movePointer : MonoBehaviour {
 // Use this for initialization
 void Start () {
 
 }
 // Update is called once per frame
 void Update () {
     transform.localScale = new Vector3(0.1f,0.1f,1.0f*Mathf.PingPong(Time.time*5.0f, 4));
     Debug.Log(transform.localScale = new Vector3(0.1f,0.1f,1.0f*Mathf.PingPong(Time.time*5.0f, 4)));
 }
 }

I know I havent explained what I want well so pls see the below image for a clearer explanation

alt text

current both ends move i only want one end to move

Any help is appreciated

a.png (16.7 kB)
a.png (16.7 kB)
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 Bunny83 · Feb 24, 2013 at 03:48 AM 2
Share

Some points:

  • Why did you upload the same image twice?

  • Why is more than half of the image empty?

  • Your problem actually isn't related to $$anonymous$$athf.PingPong, so why this question title?

So i suggest for the future to take some time when you write a question. Check if you have included everything that's necessary to understand your question. Check that there are no obvious spelling mistakes and if the question title actually fits your question. If you post images make sure they aren't too big or contain mainly useless things. You should crop the image to the relevant part. If you want / need to post a big image, you better just put a link in the post ins$$anonymous$$d of embedding the image.

4 Replies

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

Answer by Alan Fletcher · Feb 24, 2013 at 04:52 PM

as i couldnt get this going, an easy solution was sticking with the same code i had at the beginning.

Create an object in 3ds max and move it pivot point to one end, export it as an fbx file and import into unity.

Attach the script to this object and it works.

However i dont have a coded answer.

Other free 3d software will also work to do this if you cant get 3ds max

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
2

Answer by robertbu · Feb 23, 2013 at 10:23 PM

To get the behavior you want, remove the script from your block and attach it to an empty game object. Move the empty game object to the end of the block then make the block a child of the empty game object.

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 Bunny83 · Feb 24, 2013 at 03:20 AM 0
Share

I've searched my dropbox and i've found it again (i knew i've drawn one):

avatar image Alan Fletcher · Feb 24, 2013 at 02:51 PM 0
Share

Sorry dis didnt work for me, the block just disappeared on me so now i cant see this. thanks for the help though

avatar image
0

Answer by Graham-Dunnett · Feb 23, 2013 at 10:17 PM

The code example at http://docs.unity3d.com/Documentation/ScriptReference/Mathf.PingPong.html does exactly what you want.

Comment
Add comment · Show 3 · 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 robertbu · Feb 23, 2013 at 10:24 PM 0
Share

@Graham - he says "moving" but in the code he is scaling, and he is wondering how to make it scale in only one direction.

avatar image Graham-Dunnett ♦♦ · Feb 23, 2013 at 10:44 PM 0
Share

I assumed that scaling the object was a mistake. He uses non-uniform scale, which typically causes problems. But yeah, his diagrams show scaling.

avatar image Alan Fletcher · Feb 24, 2013 at 12:55 AM 0
Share

scaling is exactly what i meant sorry for confusion

avatar image
0

Answer by Pysassin · Feb 24, 2013 at 07:56 AM

You can't scale an object from one end. What you will need to do is scale and translate the object at the same time. That will give you the look you are going for.

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 Alan Fletcher · Feb 24, 2013 at 03:57 PM 0
Share

how would i do this, is it with transform.translate and transform .localScale

avatar image Pysassin · Feb 24, 2013 at 06:38 PM 0
Share

Yes. Alternatively you could just physically change the transform.position of the item as well. I personally would $$anonymous$$athf.Lerp the equation to make sure it fit without having to do complicated math. Use the start point and scale as 0 for lerps and then the 1 point as the furthest point. Then you can use the two lerps to make sure it looks the way you want. I'm not on my unity comp atm but if needed I can mock up some keep code for ya.

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

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

only detect numerical keyboard input 2 Answers

How to draw an arrow from fps contoller 1 Answer

FPS Controller rotate between two points c# 2 Answers

turn on off particle system 1 Answer

Hide the ImageTraget in Real world 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