# transform in worldspace

Hi guys,
i need some help in what i guess is actually a quite simple task, but I couldn’t figure it out for two hours.

I have a script attached to my enemy, that makes him wobble in the air:

`transform.position += amplitude*(Mathf.Sin(2*Mathf.PI*frequency*Time.time) - Mathf.Sin(2*Mathf.PI*frequency*(Time.time - Time.deltaTime)))*transform.up;`

The problem: since my enemy is angled by about 30° on the x axis, he wobbles deeper with each cycle, causing him to go through the ground.

I suppose i have to generate the direction in relation to world space, rather than its local space. But what do i use instead of transform.up, to get world space coordinates?

Dr. H

‘transform.up’ is the world direction the top of your object. If you want the world up, then you can use Vector3.up. Unless there is other code impacting this object’s rotation elsewhere, I cannot see the use of transform.up as the reason for the larger cycles. In looking at your code, I would suspect that variations in ‘deltaTime’ would make more of an impact. I only see this one line out of context, but I’d do an absolute movement based on a start position rather than rely on relative movement if I could. Example.

``````#pragma strict

var amplitude = 1.0;
var frequency = 2.0;
private var start : Vector3;

function Start () {
start = transform.position;
}

function Update () {
transform.position = start + amplitude*(Mathf.Sin(2.0 * Mathf.PI*frequency * Time.time)) * transform.up;
}
``````

This way no errors of any sort will creep in over time.