- Home /
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
current both ends move i only want one end to move
Any help is appreciated
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.
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
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.
I've searched my dropbox and i've found it again (i knew i've drawn one):
Sorry dis didnt work for me, the block just disappeared on me so now i cant see this. thanks for the help though
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.
@Graham - he says "moving" but in the code he is scaling, and he is wondering how to make it scale in only one direction.
I assumed that scaling the object was a mistake. He uses non-uniform scale, which typically causes problems. But yeah, his diagrams show scaling.
scaling is exactly what i meant sorry for confusion
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.
how would i do this, is it with transform.translate and transform .localScale
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
Follow this Question
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