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 leadObj;     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);                 leadObj.rotation = Quaternion.Slerp(leadObj.rotation, rotation, Time.deltaTime * damping);             }             else             {                 // Just lookat                 leadObj.LookAt(lookAtTarget);             }         }     }      private void Start()     {         // Make the rigid body not change rotation         if (leadObj.GetComponent<Rigidbody>() != null)             leadObj.GetComponent<Rigidbody>().freezeRotation = true;     } } 

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 leadObj;     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         if (leadObj.GetComponent<Rigidbody>() != null)             leadObj.GetComponent<Rigidbody>().freezeRotation = true;     }      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);                 leadObj.rotation = Quaternion.Lerp(leadObj.rotation, rotation, s);             }             else             {                 // Just lookat                 leadObj.LookAt(lookAtTarget);             }         }     }  } 

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;         }     } } 

How to tell MMA to transform a number to a factorial,Is there a native function?

I came across the need to transform a number into a factorial n, with positive integer n, I have searched in the MMA information but I can’t find anything like that.

I imagine an input, which verifies that it is a factorial, and if it is, prints the number in its n-form!

if there is no native function any idea how to implement it?

for example

6402373705728000=18!

51090942171709420000 does not correspond to a factorial.

Why if the targetToFollow(Player) is rotating and facing the transform the player can get close to the transform even touch it?

using System; using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; using UnityEngine.UI; using UnityStandardAssets.Characters.ThirdPerson;  public class Follow : MonoBehaviour {     public Transform targetToFollow;     public Transform missionTarget;     public GameObject naviParent;     public ThirdPersonCharacter thirdPersonCharacter;     public Text textDistance;     public Text textSpeed;     public float lookAtRotationSpeed;     public float moveSpeed;     public float followRadius = 1.5f;     public float fastRadius = 5f;     public float speedBoost = 0.5f;     public bool follow = false;     public bool reachTarget = false;      private bool isNaviChild = false;     private Vector3 lTargetDir;     private float originSpeed;     private float originFollowRadius;      void Start()     {         originSpeed = moveSpeed;         originFollowRadius = followRadius;          if (reachTarget)         {             moveSpeed = thirdPersonCharacter.m_MoveSpeedMultiplier * 5;             followRadius = 0.1f;         }     }      // Update is called once per frame     void FixedUpdate()     {         if (follow)         {             if(reachTarget)             {                 moveSpeed = thirdPersonCharacter.m_MoveSpeedMultiplier * 5;                 followRadius = 0.1f;             }             else             {                 moveSpeed = originSpeed;                 followRadius = originFollowRadius;             }              lTargetDir = targetToFollow.position - transform.position;             lTargetDir.y = 0.0f;              Turn();              float ms = moveSpeed;             var distance = Vector3.Distance(transform.position, targetToFollow.position);             // Compute a position no further than followRadius away from our target.             Vector3 fromTarget = Vector3.ClampMagnitude(                 -lTargetDir, followRadius);             Vector3 stopPoint = targetToFollow.position + fromTarget;              // Compute a speed that's faster when far away and slower when close.             float speedBlend = Mathf.Clamp01((distance - followRadius) / (fastRadius - followRadius));              ms = moveSpeed + speedBlend * speedBoost;              // Move as far as we can at our speed ms to reach the stopPoint, without overshooting.             transform.position = Vector3.MoveTowards(transform.position,                 stopPoint, Time.deltaTime * ms);              var dist = Vector3.Distance(transform.position, targetToFollow.position);             if (dist < 0.1f && isNaviChild == false && reachTarget)             {                 transform.parent = targetToFollow;                 transform.localPosition = new Vector3(0, 0, 0);                 transform.localRotation = Quaternion.identity;                 transform.localScale = new Vector3(0.001f, 0.001f, 0.001f);                  isNaviChild = true;             }         }     }      private void Turn()     {         transform.rotation = Quaternion.RotateTowards(transform.rotation,                 Quaternion.LookRotation(lTargetDir), Time.time * lookAtRotationSpeed);     }      private void Mission()     {      } } 

When the bool flag follow is true and the bool flag reachTarget is false the transform that this script is attached to is moving towards the targetToFollow and then when the targetTofollow(in this case the target is the player that move by the kleys WSAD) move the transform is following him with keeping distance to follow that’s the followRadius.

The problem is that if I rotate my place to face the transform and then moving the player forward he will be able to get too close to the transform even touching it.

But in my logic if the radius to follow is 1.5 so even if the player will face the transform and try to move forward to it the transform should always move to the back of the player or move back and keep the follow radius of 1.5 or if the follow radius is 66.3 then 66.3

The player should not be able to get so close to the transform.

How can I solve it ?

Numerical issues in Fourier transform of Mathieu functions

I’m trying to calculate the Fourier transform of the Mathieu $ \text{me}$ functions using NIntegrate but keep on getting NIntegrate::inumr (the integrand has evaluated to non-numerical values) and NIntegrate:ncvb (failed to converge to prescribed accuracy) errors. Here is how I’m defining the Mathieu functions

ce[r_, z_, q_] := MathieuC[MathieuCharacteristicA[r, q], q, z] se[r_, z_, q_] := MathieuS[MathieuCharacteristicB[r, q], q, z] me[r_, z_, q_] := (ce[r, z, q] + I se[r, z, q]) / Sqrt[2 Pi] 

and I’m evaluating the integral

NIntegrate[Exp[-I n z] / Sqrt[2 Pi] me[r, z, q], {z, 0, 2 Pi}] 

where r is very close to an integer (I avoid exact integers because MathieuCharaceristicA and MathieuCharaceteristicB are not continuous at integers) and q for example varies continuously from -70 to 0.

Does anyone know how I can get around the numerical issues? Or is there a more efficient way to numerically Fourier transform Mathieu functions?

Where does the Transform Vampires/Werewolves into lawn furniture rote come from?

I remember the 90s when Mage players would tell Vampire players that a Mage can very easily transform a Vampire or Werewolf into lawn chairs, and that they could get quite a good collection. I didn’t know much about Mage those days, and I always supposed that was covered in some supplement.

These days, after reading some Mage books, I’m not so sure.

Was that infamous rote published in an official book? Which?

If not, anyone knows its origin? How did it spread so fast?

You can find the rote on page 610 of M20 as a kind of a joke. But I’m asking about the old days.

SQL to transform all email addresses in my DB in lowercase

how can I transform all email addresses in my DB in lowercase?

I did an import and all addresses are uppercase and if a user registers again with lowercase the system thinks is another email. So I want to change all the emails to lower to avoid further duplications.

best will be to have a SQL query to do that

Thanks for your help!

MySQL Transform multiple rows into a single row in same table (reduce by merge group by)

Hy, i want reduce my table and updating himself (group and sum some columns, and delete rows)

Source table "table_test" :

+----+-----+-------+----------------+ | id | qty | user  | isNeedGrouping | +----+-----+-------+----------------+ |  1 |   2 | userA |              1 | <- row to group + user A |  2 |   3 | userB |              0 | |  3 |   5 | userA |              0 | |  4 |  30 | userA |              1 | <- row to group + user A |  5 |   8 | userA |              1 | <- row to group + user A |  6 |   6 | userA |              0 | +----+-----+-------+----------------+ 

Wanted table : (Obtained by)

DROP TABLE table_test_grouped; SET @increment = 2; CREATE TABLE table_test_grouped SELECT id, SUM(qty) AS qty, user, isNeedGrouping FROM table_test GROUP BY user, IF(isNeedGrouping = 1, isNeedGrouping, @increment := @increment + 1); SELECT * FROM table_test_grouped;  +----+------+-------+----------------+ | id | qty  | user  | isNeedGrouping | +----+------+-------+----------------+ |  1 |   40 | userA |              1 | <- rows grouped + user A |  3 |    5 | userA |              0 | |  6 |    6 | userA |              0 | |  2 |    3 | userB |              0 | +----+------+-------+----------------+ 

Problem : i can use another (temporary) table, but i want update initial table, for :

  • grouping by user and sum qty
  • replace/merge rows into only one by group

The result must be a reduce of initial table, group by user, and qty summed.

And it’s a minimal exemple, and i don’t want full replace inital from table_test_grouped, beacause in my case, i have another colum (isNeedGrouping) for decide if y group or not.

For flagged rows "isNeedGrouping", i need grouping. For this exemple, a way to do is sequentialy to :

CREATE TABLE table_test_grouped SELECT id, SUM(qty) AS qty, user, isNeedGrouping FROM table_test WHERE isNeedGrouping = 1 GROUP BY user ; DELETE FROM table_test WHERE isNeedGrouping = 1 ; INSERT INTO table_test SELECT * FROM table_test_grouped ; 

Any suggestion for a simpler way?

How to transform robot motor steps into X/Y coordinates?

I have a robot with two motors A and B connected to wheels 21.6mm in diameter. The motors move in steps, and there are twenty steps for each complete revolution of the wheel. To make the robot move forwards, I turn on A and B in the forward direction and have it rotate a number of steps. To make it move backwards, I turn on A and B in the reverse direction. To get it to turn left, I turn on A and turn off B. Similarly to get it to turn right, I turn off A and turn on B. Using this scheme, I can get the robot to move in any direction.

My question is this: is it possible to transform the steps of motor A and motor B into the X/Y coordinates for the robot? For example, if I move the robot forward 10 steps, turn right 10 steps and move forwards again 10 steps can I calculate the X/Y coordinates of the robot? Assume that the robot starts at point 0,0.

Discrete fourier transform in different forms

For the discrete Fourier transform, it is defined by

$ $ f(k)=\sum_{s_i}\exp(-iks)\phi(s).~~~~~~~~~~~~~~~~~(ds-1)$ $ here $ s_i=-(N-1)/2,-(N-2)/2,…..(N-1)/2$ .

For convenience, we also add the continuous Fourier transform

$ $ f(k)=\int_{-\infty}^{\infty}\exp(-iks)\phi(s)ds~~~~~~~~~~~~~~~~~(cn-1)$ $

It can be seen that for the discrete case, the integral of the right-hand side of Eq.~(cn-1) is chosen at some special point, i.e., $ s_i=-(N-1)/2,-(N-2)/2,…..(N-1)/2$ . If you take $ N\to \infty$ , the above two formulas should consistent with each other.

While for the inverse discrete Fourier transform, it reads

$ $ \phi(s)=\frac{1}{N}\sum_{k_i}\exp(iks)f(k),~~~~~~~~~~~~~~~~~(ds-2)$ $ where $ k_i=-\frac{2\pi}{N}\frac{N-1}{2},……\frac{2\pi}{N}\frac{N-1}{2}$ . Let $ N\to \infty$ , Eq.~(ds-2) can be shown by $ $ \phi(s)=?\frac{1}{N}\int_{-\pi}^{\pi}\exp(iks)f(k)dk~~~~~~~~~~~~~~~~~(ds-3)$ $ I believe Eq.~(ds-3) is wrong if you let $ N\to \infty$ .

I see that in some books, they use

$ $ \phi(s)=\frac{1}{2\pi}\int_{-\pi}^{\pi}\exp(iks)f(k)dk~~~~~~~~~~~~~~~~~(ds-4)$ $

Question 1): how to understand the equation (ds-3) and (ds-4). Why $ N$ should be replaced by $ 2\pi$ ?

Question 2): If N is finite, we can use Eq.~(ds-1) for the discrete Fourier transform, and the inverse is given by (ds-2). While, for the discrete case, if $ N\to \infty$ , how can I get the inverse discrete Fourier transform? Can we use Eq.~(ds-2)? But If $ N\to \infty$ , it seems that Eq.~(ds-2) is not correct.

Question 3) If $ N\to \infty$ , can we use the continuous Fourier transform, i.e., $ $ \phi(s)=\frac{1}{2\pi}\int_{-\infty}^{\infty}\exp(iks)f(k)dk~~~~~~~~(cn-2)$ $ to estimate Eq.~($ ds-2$ )? It seems that Eq.($ ds-4$ ) is different from Eq.~(cn-2). Is there some relation between Eq.~(ds-4) and Eq.(cn-2).

Question 4, whih formula is the discrete inverse Fourier tansfom in the limit of $ N\to \infty$ ?

Any suggestions or related URL or books are welcome! Thanks!