x


Add a wave to a Translate

Hi,

im new on unity, and on game programming. I'm trying to make a translate of a missile a little more than a simple transform.forward, im trying to add two waves on x and y axies.

here is the working code:

function Update () {

transform.Translate(Vector3.forward*60*Time.deltaTime);

}

here is the wrong code:

private var player:GameObject;

player=gameObject.Find("Player");

private var distanceToPlayer:float;

distanceToPlayer=Vector3.Distance(transform.position,player.transform.position);

private var numIteration:float;

numIteration=1;

private var waveHeight:float;

waveHeight=1;

private var ondex:float;

private var ondey:float;

function Update () {

var ondex=waveHeight*Mathf.Sin((transform.position.x/distanceToPlayer)*Mathf.PI*numIteration);
var ondey=waveHeight*Mathf.Sin((transform.position.y/distanceToPlayer)*Mathf.PI*numIteration);
transform.Translate(ondex,ondey,Vector3.forward*60*Time.deltaTime,Space.World);

}

Can you help me? Thx

more ▼

asked Jul 22 '11 at 02:33 PM

malakief gravatar image

malakief
1 1 1 1

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

i forgot the error message: BCE0023: No appropriate version of 'UnityEngine.Transform.Translate' for the argument list '(float, float, UnityEngine.Vector3, null)' was found. i don't understand this error :(

more ▼

answered Jul 22 '11 at 02:35 PM

malakief gravatar image

malakief
1 1 1 1

(comments are locked)
10|3000 characters needed characters left

The problem is you are passing the wrong argument in transform.Translate.

The third value in transform.Translate is an entire Vector3 instead of a float. Unity expects a single float value for the z coordinate of the translation, but you are giving it an entire vector so it doesn't know how to use it.

You should write:

var ondex=waveHeight*Mathf.Sin((transform.position.x/distanceToPlayer)*Mathf.PI*numIteration);
var ondey=waveHeight*Mathf.Sin((transform.position.y/distanceToPlayer)*Mathf.PI*numIteration);
transform.Translate(ondex,ondey,60*Time.deltaTime,Space.World); // we took out the Vector3.forward
more ▼

answered Jul 22 '11 at 02:59 PM

drChengele gravatar image

drChengele
31 1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x206
x41
x41
x20

asked: Jul 22 '11 at 02:33 PM

Seen: 662 times

Last Updated: Jul 22 '11 at 02:59 PM