## unity – Why the transform is not looking at the target?

The goal is to make smooth rotating look at.

The parent object is my character have a Rigidbody.

The script is attached to the character parent.
I make a reference to the character child name head.

I have a cube as the target the cube is rotating around the character with random height.

The character is never looking at the cube.
I tried to change from LateUpdate to Update I tried to add a child of the head empty gameobject and reference the empty gameobject but still the character head is not rotating to the target.

``````using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SmoothLookAt : MonoBehaviour
{
public Transform lookAtTarget;
public float damping = 6;
public bool smooth = true;

private void LateUpdate()
{
if (lookAtTarget)
{
if (smooth)
{
// Look at and dampen the rotation
var rotation = Quaternion.LookRotation(lookAtTarget.position - leadObj.position);
}
else
{
// Just lookat
}
}
}

private void Start()
{
// Make the rigid body not change rotation
}
}
``````

It seems to be working if I reference the head directly as leadObj and inside LateUpdate the problem is that I have to set the damping value to 260.

Why I need to set the damping value to be so high ?

And how can I make that the head will rotate to the target with automatic speed depending on the target moving speed ? So if I don’t set any damping value for example 0 or null it will automatic calculate the needing speed to rotate facing the target ?

I see now another problem. If I set the damping value to 100 for example the character head is stuttering the head will look at the target but will stuttering.
I want that if the damping value is 100 or lower than rotate the leadObj with a delay facing the target. Something like when a turret is rotating facing a missile and if the missile is moving too fast the turret is rotating with some delay because he rotate slower.
How can I do it ?

This is working using Lerp. But why if I set for example the duration value to 0 it’s not affecting the speed of the leadObj rotation ?

The leadObj keep rotating same speed facing the target even if the duration is 0.

What am I missing ?

``````using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SmoothLookAt : MonoBehaviour
{
public Transform lookAtTarget;
public float duration;
public bool smooth = true;

private float t = 0.0f;

private void Start()
{
// Make the rigid body not change rotation
}

private void LateUpdate()
{
if (lookAtTarget)
{
if (smooth)
{
t += Time.deltaTime;
float s = t / duration;

// Look at and dampen the rotation
var rotation = Quaternion.LookRotation(lookAtTarget.position - leadObj.position);
}
else
{
// Just lookat
}
}
}
}
``````

## complex analysis – Imaginary differential into fourier transform

I’ m looking for a way to relate the Fourier trasform in the form
$$tilde F[vec q] = int d^2x , e^{i vec q cdot vec x} fleft[ sqrt{x^2 + d^2} right],$$

and the fourier transform

$$F'[vec q] = int d^2x , e^{i vec q cdot vec x} fleft[ vert x vert right],$$

by trasnforming the first integral with the change of variables $$vec x rightarrow vec x – i vec d$$, with $$vec d parallel vec q$$.

As a result, I expect to see :

$$tilde F[vec q] = e ^ {- q d} F'[vec q],$$

but the procedure would require to go into the complex plane and doesn’ t seem intuitive how to get the expected result. Is there any hint to get there?

## matrices – Hadamard Transform application example

I am trying to use the Hadamard transform on a delta function to generate Hadamard patterns as shown below.

$$tag{4} P_Hleft(x,yright)=frac{1}{2}left(1+H^{-1}left{delta _Hleft(u,vright)right}right)$$
Where $$H^{-1}left{right}$$ denote an inverse Hadamard transform and
$$tag{5}delta _Hleft(u,vright)=begin{cases}1, space u=u_0, v=v_0\0,space text{otherwise} end{cases}$$

However, I am not sure what the delta function is supposed to do. Could anyone show me a simple example with real values of x,y,u, and v so that I can learn what to do?

## polar coordinates – 2D Fourier transform – apparently vanishing dependance on angular variable

I am rather confused about the 2D Fourier transform (FT) of a certain function, and would appreciate some thoughts:)

I have a function $$f(mathbf x)=g(x)cos(4theta)$$, where the function $$g(x)$$ only depends on the radial coordinate, and $$theta$$ is the angular coordinate of $$mathbf x$$. Now I want the 2D FT $$F(mathbf k)$$ of that function $$f(mathbf x)$$. So I write:

$$F(mathbf k)=frac{1}{sqrt{2pi}}int x, dx dtheta, g(x)cos(4theta) exp(-imathbf xcdotmathbf k)$$, taking $$mathbf k || mathbf{hat e_x}$$, I can write this as
$$F(mathbf k)=frac{1}{sqrt{2pi}}int x, dx dtheta, g(x)cos(4theta) exp(-i x k cos(theta))$$. Now I can do the integral over the angular variable (using e.g. this Simpler proof of an integral representation of Bessel function of the first kind \$J_n(x)\$)

$$F(mathbf k)=sqrt{2pi}int x, dx, g(x)J_4(xk)=F(k)$$ so the angular dependence completely disappeared for the FT. But when I transform back, I the angular depence does not re-appear:

$$f(mathbf x)=frac{1}{sqrt{2pi}}int k, dk dalpha, F(k) exp(-imathbf xcdotmathbf k)=frac{1}{sqrt{2pi}}int k, dk dalpha, F(k) exp(-ix k cos(alpha-theta))=sqrt{2pi}int k, dk, F(k)J_0(kx)$$

so I assume that the angular dependance vanished because of the implicit choice of coordinates $$mathbf k || mathbf{hat e_x}$$. But if this is the case, I think I should be able to do such a coordinate transform directly such that $$f(mathbf x)=f(x)$$, but I don’t see it…

Or am I completely misunderstanding/miscalculating something here? Thanks very much in advance for any clarifications!

## unity – Reorientation when rotating Transforms around another Transform without parenting

The functionality I am trying to implement, consists of rotating one Transform and appling this rotation to other relevant Transforms in the scene. To make it a bit more clear: I have several objects in the scene. When I grab one (lets call it parent) and rotate it, the others (children) should rotate relative of their own position and rotation to the grabbed object around this grabbed object.

It is exactly the same what parenting does with its child objects when rotating the parent. Unfortunatly I cant just change the hierachy so I am bound to have different objects on the same hierachy level.

So far I have managed to rotate the children relative to the parent but when I grab the parent object the child objects first reorient themselves. After reorienting they do the right thing and rotate and move relative to the parent.

Here are two objects. The left one should rotate relative to the right one.

As the right one is grabbed and the procedure starts, the child object first jumps to another position with another rotation

I feel kind of stupid not seeing where this behaviour comes from.
I use a coroutine to be able to construct the functionality in another script.
As long as the coroutine is running, the child object should be moved and rotated relatively.

I first calculate the needed offsets of the position and rotation at startup:

``````    Vector3 offsetPos = child.position - parent.position;
Quaternion offsetRot = child.rotation * Quaternion.Inverse(parent.rotation);
``````

Then I apply the calculations in a loop:

``````    while (true)
{
child.position = parent.rotation * offsetPos + parent.position;
child.rotation = parent.rotation * offsetRot;

yield return new WaitForFixedUpdate();
}
``````

The loop runs as long as the parent object is grabbed and should place and orient the child accordingly.

I assume that my fault is located somewhere around calculating the offsets as once grabbed and reoriented, the children move and rotate exactly as they should.
If somebody has an idea where my mistake could hide I would be really happy if you could tell me.

Here is the related function as a whole:

``````    public override IEnumerator TransformGroupMember(Transform child, Transform parent)
{
//calculate offsets
Vector3 offsetPos = child.position - parent.position;
Quaternion offsetRot = child.rotation * Quaternion.Inverse(parent.rotation);

//apply the relative transformation as long as the coroutine is running
while (true)
{
child.position = parent.rotation * offsetPos + parent.position;
child.rotation = parent.rotation * offsetRot;

yield return new WaitForFixedUpdate();
}
}
``````

Since this is my first question asked, I also welcome any suggestions about tips and tricks or changes.

## Problem

I am looking for the following inverse Laplace transform,
$$f(t) = mathcal{L}^{-1}left(frac{1}{s^a + 1}right) ;;;;; text{with} ;;;;; 0 < a leq 1.$$

## What I understand

• with $$a = 1$$, $$f(t) = e^{-t}$$

• for small $$t ll 1$$, $$f(t)$$ should behave
$$f(t)approx frac{1}{Gamma(a)} t^{a-1}$$
as
$$frac{1}{s^a + 1} approx s^{-a}$$
with large $$sgg 1$$

• for large $$t gg 1$$, $$f(t)$$ should behave
$$f(t) approx frac{a}{Gamma(1-a)} t^{-(a+1)}$$
from
$$t f(t) = mathcal{L}^{-1}left(frac{a s^{a-1}}{(s^a + 1)^2}right) approx mathcal{L}^{-1}left(a s^{a-1}right)$$
with small $$s ll 1$$.

## Numerical solution

I have a master equation for $$f(t)$$ and the above Laplace transform is obtained from this master equation.
By numerically solving the master equation, I obtained the following numerical solution,

But I want an analytical representation (even an approximated one), not the numerical solution.

## Candidates?

Since the solution may smoothly connect between these two limit forms, and should be similar to the exponential function if $$aapprox 1$$, I expected something similar to the kappa distribution,
$$t^{a-1}left(1 + frac{t}{a+1}right)^{-(a+1)}$$.
However, the exponent does not match, and this does not reproduce both the Laplace transform and the numerical solution.

Wolfram alpha does not give a solution, either.

Any idea would be appreciated.

## calculus and analysis – Fourier transform of \$ exp{left(text irx/sqrt{1-text ix}right)}/(1-text ix) \$

I want to calculate the following Fourier transform:

$$u(r,t) = int_{-infty}^{infty}text domega frac{1}{1-text iomega}, expleft{frac{text ir omega}{sqrt{1-text i omega}} +text iomega tright}$$

However, when I try to put it in Mathematica, both

``````FourierTransform(Exp(I r x/Sqrt(1 - I x))/(1 - I x), x, t, Assumptions -> r > 0)
``````

and

``````Integrate(Exp(I r x/Sqrt(1 - I x) + I x t)/(1 - I x), {x, Infinity, Infinity}, Assumptions -> r > 0 && t (Element) Reals)
``````

`FourierTransform` and `Integrate` commands, I get nothing the same command printed at the output after a while. Is there any other way to calculate this integral symbolically?

## analysis – Fourier Transform of \$frac{1}{|x|^2-1}\$ in \$mathbb{R}^3\$

I’m trying to calculate the Fourier transform of
$$F(vec{r}) = frac{1}{|vec{r}|^2 – 1},$$

where $$vec{r}inmathbb{R}^3$$, in the sense of tempered distributions. I want to get it to find the inhomogeneous wave equation fundamental solution with Fourier analysis. in I think it is related to the principal value distribution, but I have not managed to solve it until now…

## unity – Why when I move the transform closer to the target by dragging it in the editor in the scene view the target start stuttering and moving back?

The script is attached to a transform that move to a target and than when reaching the target the transform become child of the target.

The script is working fine as it is now but if I drag with the mouse in the editor in the scene view the target to the moving transform while the transform is already moving to the target then the transform start stuttering and even moving back a bit like pushed back some forces pushing it back maybe because I’m using lerp in lines 55,56 ? I want to use lerp but maybe it’s making the problem?

Second if I move the target away from the transform instead trying to chase me and reaching me its doing this problems again.

I want that if I’m dragging and make the target closer to the moving transform than just keep the transform moving to the target and become child when they reaching each other and if I drag the target away from the transform make the transform try to chase me reach me and become child too.

``````using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MoveToTarget : MonoBehaviour
{
public enum TransitionState
{
None,
MovingTowards,
Transferring
}

public Transform destinationTransform;
public float speed;
public float lerpTime;
public bool isChild = false;

public AnimationCurve curve = AnimationCurve.EaseInOut(0.0f, 0.0f, 1.0f, 1.0f);
public Transform start;
public Transform end;
public float duration = 10.0f;
private float t;

private Transform originTransform;
private float timer;
private TransitionState state = TransitionState.MovingTowards;
private Vector3 originTrans;

void Start()
{
t = 0.0f;

curve.postWrapMode = WrapMode.PingPong;
originTrans = transform.position;
}

void Update()
{
switch (state)
{
case TransitionState.MovingTowards:
var v = destinationTransform.position - transform.position;
if (v.magnitude < 0.001f)
{
state = TransitionState.Transferring;
originTransform = destinationTransform;
timer = 0;
return;
}
Vector3 moveDir = v.normalized;
//transform.position += moveDir * speed * Time.deltaTime;
t += Time.deltaTime;
float s = t / duration;
transform.position = Vector3.Lerp(originTrans,
destinationTransform.position, curve.Evaluate(s));
break;

case TransitionState.Transferring:
timer += Time.deltaTime;
this.transform.position = Vector3.Lerp(originTransform.position, destinationTransform.position, timer);
if (timer >= 1.0f)
{
this.transform.parent = destinationTransform;
isChild = true;
state = TransitionState.None;
this.enabled = false;
return;
}
break;

default:
this.enabled = false;
return;
}
}
}
``````

## performance – 2D Discrete Fourier Transform using Fortran

I am solving the 2D Wave Equation using Fourier Transform. The Discrete Fourier Transform (and the inverse also) is done inside the `kx`-loop and `ky`-loop. But this code runs slow, is there anyway to make it much more efficient? I guess the `kx`-loop, `ky`-loop inside the `i`-loop and `j`-loop makes it slow. I am also open for external package suggestion.

``````program fourier_transform_solution
implicit none

integer :: i,j,kx, ky, it
real, parameter :: PI = 3.1415926
integer, parameter :: N=100, N_t=100
integer, parameter :: N_k = N/2
real, dimension(N):: x, y
real, dimension(N,N) :: f, ut_init, u_r
real, dimension(N_t) :: t
complex, dimension(N,N) :: u, u_hat, u_hat_prev, ut_hat, ut_hat_prev
complex, dimension(N) :: wx, wy
complex, parameter :: I_complex = complex(0, 1)
real :: dx, xmin=0, xmax=3*PI, dy, ymin = 0, ymax = 3*PI
real :: d, dt = 0.001

do i=1,N_t,1
t(i) = 0 + (i-1)*dt
end do

dx = (xmax-xmin)/(N-1); dy = (ymax-ymin)/(N-1); d = dx/(2*PI);

do i=1,N_k,1
wx(i) = 0 + -(N_k-i)/(d*(N-1)); wx(N_k+i) = 0 + (i)/(d*(N-1))
wy(i) = 0 + -(N_k-i)/(d*(N-1)); wy(N_k+i) = 0 + (i)/(d*(N-1))
end do

do i=1,N,1
x(i) = xmin+ (i-1)*dx
y(i) = ymin+ (i-1)*dy
end do

do i=1,N,1
do j=1,N,1
f(i,j) = 0.6*exp( -((x(i)- 1.5*PI)**2) + -((y(j)- 1.5*PI)**2)  )
u(i,j) = f(i,j)
u_r(i,j) = f(i,j)
ut_init(i,j) = 0
end do
end do

!Fourier Transform
do i=1,(N),1
do j=1,N,1
u_hat_prev(i,j) = 0
ut_hat_prev(i,j) = 0
do kx=1,N,1
do ky=1,N,1
u_hat_prev(i,j) = u_hat_prev(i,j) + u_r(kx, ky)*exp(-(wx(i)*x(kx) + wy(j)*y(ky))*(I_complex))
ut_hat_prev(i,j) = ut_hat_prev(i, j) + ut_init(kx, ky)*exp(-(wx(i)*x(kx) + wy(j)*y(ky))*(I_complex))
end do
end do
end do
end do

do it=2,N_t,1

do i=1,(N),1
do j=1, N, 1
ut_hat(i, j) = ut_hat_prev(i, j) + dt*(-(wx(i) + wy(j))**2)*(u_hat_prev(i, j))
end do
end do

do i=1,(N),1
do j=1,N,1
u_hat(i,j) = u_hat_prev(i,j) + dt*ut_hat(i,j)
end do
end do

!Inverse Fourier
do i=1,N,1
do j = 1,N,1
u(i, j)=0
do kx=1,N,1
do ky=1,N,1
u(i,j)  = u(i,j) + u_hat(kx, ky)*exp((I_complex)*(wx(kx)*x(i) + wy(ky)*y(j)))
end do
end do
u_r(i,j) = (real(u(i,j)))/(N*N)
ut_hat_prev(i,j) = ut_hat(i,j)
u_hat_prev(i,j) = u_hat(i,j)
end do
end do
print *, it
end do

end program fourier_transform_solution
$$```$$
``````