Archive 17/01/2023.

Urho’s equivalence to Unity

smellymumbler

I’m having some trouble porting some Unity scripts to Urho, but nothing really fancy. Could anyone point me to the right direction when it comes to the equivalence of these calls?

  • Unity allows you to get the gravity from scripts via Physics.gravity.y, Physics.gravity.x, etc. What’s the Physics object in Urho?
  • What would be the equivalent of Mathf.Max?
  • What would be the equivalent of Controller.transform? Can i get the X/Y/Z of a node? What about its velocity?
  • Vector3.Scale. Is there something similar in Urho?
  • Vector3.sqrMagnitude: https://docs.unity3d.com/ScriptReference/Vector3-sqrMagnitude.html
Eugene
  1. Something like physicWorld in AS, GetScene/GetComponent in C++
  2. Max?
  3. Check Controller’s code, there shall be something like RigidBody
  4. LengthSquare or like this.
smellymumbler
  1. So, something like scene->GetComponent()->GetGravity().y_?
  2. Max… ? max()?
  3. I’ve checked the controller code, but what’s the equivalent of the transform? myRigidBody->GetPosition().x_?
  4. Any vec3 * vec3 will multiply all the components of the vector?
smellymumbler

Also, is there an equivalent of this?

https://docs.unity3d.com/ScriptReference/Transform.TransformDirection.html

Modanung

That would be Node::LocalToWorld.

smellymumbler

Thank you so much! :slight_smile:

Modanung

To use Max() you need to include Math/MathDefs.h

Yup

smellymumbler

Thanks a lot for the info. There’s another thing confusing me which is the fact that Unity has too global variables: Time.deltaTime and Time.time.

https://docs.unity3d.com/ScriptReference/Time.html

It seems that Urho only has a deltaTime, that is called timestep and it’s sent to all Update() functions. How do i get Time.time?

Modanung

GetSubsystem<Time>()->GetElapsedTime() gives you the time in seconds the program has been running. Calling GetSystemTime() on the Time subsystem gives you the system time in msec.
In Urho3D time scales are set per scene.

smellymumbler

What about the time since the beginning of the frame?

Modanung

Well… the timestep is the amount of time since the last frame. Which means according to that measurement the current frame just started and has been lasting for about 0 seconds. Does that answer your question?

smellymumbler

Not really… i thought that the timestep was the time in seconds it took to complete the last frame. Urho3D timestep = Unity Time.deltaTime. If that’s not it, then timestep is the time since the frame started?

smellymumbler

Is there an equivalent for https://docs.unity3d.com/ScriptReference/Vector3.ClampMagnitude.html?

Lumak
Vector3 ClampMagnitude(const Vector3 &vec, float maxLen)
{
    Vector3 retVec = vec;

    if (retVec.Length() > maxLen)
        {
            retVec = retVec.Normalized() * maxLen;
        }

        return retVec;
}

smellymumbler

Thanks! Is it possible to extend the original Vector3 class with such additions? Monkey-patch it?

Modanung

You could maintain your own fork of the engine or send in a pull request. For consistency’s sake I’d name this function ClampLength.

smellymumbler

Oh, i couldn’t do that. Lumak wrote the amazing code. He should send a PR, this is an amazing addition. Thanks a lot for the help and the attention, guys.

Hope this thread helps other Unity guys coming to Urho.

Eugene

[offtop]
I think that inbuilt C# scripts in Urho would be perfect…
Unfortunatelly, those clever volunteers somewhy always create hard-to-reuse forks like Atomic or UrhoSharp.