How do can I make rotation Loop with verse?

Basically Im trying to make this bars moving, like the original game:

I have this code but I dont know how to start rotating it when the game starts:


using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /Verse.org/Simulation/Tags }

 LowBar := class(tag){}


hello_world_device := class(creative_device):

    rota()<suspends> : void =
        TaggedDevices := GetCreativeObjectsWithTag(LowBar{}) 


    OnBegin<override>()<suspends>:void=
        rota()
        

    

The lowbar has the LowBar label assigned btw
Thanks <3

1 Like

Code like this should work

hello_world_device := class(creative_device):

    @editable LowBar:creative_prop = creative_prop{}
    @editable RotationsPerSecond:float = 0.5

    OnBegin<override>()<suspends>:void=

        loop:
            PropTransform := LowBar.GetTransform()
            LowBar.MoveTo(PropTransform.Translation, PropTransform.Rotation.ApplyLocalRotationZ(360.0), RotationsPerSecond)

If you want to use tags and your LowBar is a prop then you can use

TaggedDevices := GetCreativeObjectsWithTag(LowBar{})
        
if (LowBarProp := creative_prop[TaggedDevices[0]]):
    loop:
        PropTransform := LowBarProp.GetTransform()
        LowBarProp.MoveTo(PropTransform.Translation, PropTransform.Rotation.ApplyLocalRotationZ(360.0), RotationsPerSecond)
2 Likes

Thanks a lot for the fast answer!

Is there any way to fix why its seems to be not compatible with my config?

When im trying to add it, i get the not compatible message!

Thanks again! <3

To be able to manipulate your own custom mesh as a creative_prop you need to go through the steps to make a custom prop out of your mesh, which are described here Converting Assets into Props. Is that the issue you are encountering?

I’m also facing an error related to this. I have all like you said but when I run the game this error is shown: Error: VerseRuntimeErrors: GetTransform called on disposed object. Use .IsDisposed[] to check before calling.

Did you assign the MyProp field in the editor to the prop in the map you want to rotate?

From here is everything working!

I can only say thanks!

Now I will see why flicks like that, but that’s a minor bug.

Tom from now you are better than ChatGPT! haha <3

2 Likes

I was cheking everything in the editor but I do not found anything that could help me to fix this issue.

My code is running twitce when the loop starts.

I mean, MoveTo is executing slower than the loop, then if I code 1 sec in OverTime on MoveTo, the rotating bar start flashing because its trying to do two movements in one.

Is there any way to fix this issue? I tryied with Sleep(SpeedTime) but its always stopping double time than MoveTo function.

Thanks again.

1 Like

MoveTo and the loop should not be getting out of sync so that looks like a bug. Thanks for the report, we’ll get it investigated.

Hi again!

I finnaly found this way to fix it and I hope that the comunity could use it until you can fix it.

Here is the code fully code!

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /Verse.org/Simulation/Tags }
using { /Verse.org/Concurrency }

# A Verse-authored creative device that can be placed in a level
RotateLowBar := class(creative_device):

    @editable LowBar:creative_prop = creative_prop{}
    @editable RotationsPerSecond:float = 60.0

    var Speed:float = 0.7

    muevelo()<suspends>:void=
            var result: move_to_result = LowBar.MoveTo(LowBar.GetTransform().Translation, LowBar.GetTransform().Rotation.ApplyLocalRotationZ(360.0),(Speed))
            if(result = move_to_result.DestinationReached):
                muevelo()

    OnBegin<override>()<suspends>:void=
        muevelo()

Regards <3

4 Likes

FYI:
The animation_controller obtained from GetAnimationController was designed for much smoother keyframed animation.

if (AnimController := MyProp.GetAnimationController[]):
            AnimationKeyframes := array{
                keyframe_delta{DeltaLocation:=vector3{X:=0.0, Y:=-85.33, Z:=16.67}, DeltaRotation:=MakeRotation(Axis:=vector3{X:=0.0, Y:=0.0, Z:=1.0}, AngleRadians:=0.0), Time:=3.0},
                keyframe_delta{DeltaLocation:=vector3{X:=0.0, Y:=-85.33, Z:=16.67}, DeltaRotation:=MakeRotation(Axis:=vector3{X:=0.0, Y:=0.0, Z:=1.0}, AngleRadians:=0.0), Time:=3.0}}

            AnimController.SetAnimation(Keyframes:=AnimationKeyframes, ?Mode:=animation_mode.PingPong)
            AnimController.Play()

There’s currently a bug if all the keyframe Time variables aren’t the same, but that will be fixed in the future.

2 Likes

Still can not solve the lag issue.

    ActivateMiniGun() <suspends>: void={
        Print("Pulsado")
       # MiniGunMeshtransform := MiniGunMesh.GetTransform()
       # var MiniGunPosition : vector3 = MiniGunMesh.GetTransform().Translation
       # MiniGunMesh.MoveTo(MiniGunPosition, MiniGunMeshtransform.Rotation.ApplyLocalRotationY(360.0), RotationsPerSeconds)
        var Speed:float = 0.7
        var result: move_to_result = MiniGunMesh.MoveTo(MiniGunMesh.GetTransform().Translation, 
        MiniGunMesh.GetTransform().Rotation.ApplyLocalRotationY(360.0),(Speed))
        if(result = move_to_result.DestinationReached):
            ActivateMiniGun()
    }   
1 Like

Hi Klandar.

I don´t know how this exactly works, but is not doing antything at all :confused:

Here is an example of using the animation_controller to rotate a prop in a full circle.

if (AnimController := RotatingPipe.GetAnimationController[]):
    AnimationKeyframes := array:
        keyframe_delta:
            # No translation
            DeltaLocation := vector3{}
            # Rotate 180 degrees
            DeltaRotation := MakeRotation(Axis := vector3{ X:=0.0, Y:=0.0, Z:=1.0 }, AngleRadians := PiFloat)
            Time := 1.5
        keyframe_delta:
            # No translation
            DeltaLocation := vector3{}
            # Rotate 180 degrees
            DeltaRotation := MakeRotation(Axis := vector3{ X:=0.0, Y:=0.0, Z:=1.0 }, AngleRadians := PiFloat)
            Time := 1.5
    AnimController.SetAnimation(Keyframes := AnimationKeyframes, ?Mode := animation_mode.Loop)
    AnimController.Play()

If this isn’t working there are two things you can check. First, it could be that GetAnimationController[] fails which means the whole block is skipped. Second, it could be that the prop you are trying to animate is not animatable. To check this you can check if (AnimationController.GetState() = animation_controller_state.InvalidObject).

4 Likes

@Incredulous_Hulk
Thanks for that code sample! It works really well when the object isn’t rotated, but it can cause desync when the object is already rotated. Maybe there is ambiguity about which direction it should rotate since it’s the same distance rotating either direction. I think it’s fixed by picking a smaller increment than PI. I went in 4 deltas of 1/2 PI each and that seems to work.
Thanks!

2 Likes

Sounds like the quaternion interpolation checkbox we do in the sequencer, which helps solve it there, so maybe if you try to replicate what that setting does in code, it may solve it.