Urho's equivalence to Unity

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
  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.
  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?

Also, is there an equivalent of this?

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

That would be Node::LocalToWorld.

Thank you so much! :slight_smile:

1 Like

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

Yup

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?

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.

What about the time since the beginning of the frame?

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?

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?

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

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

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

        return retVec;
}

2 Likes

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

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.

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.

[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.