Results 1 to 11 of 11
  1. #1
    MSgt. Shooter Person
    Join Date
    Nov 2009
    Posts
    45

    Default Detecting KActor Stopped moving

    Hi,

    I'm programming a golf game in UDK and I'm having troubles trying to find out how to detect when the ball has stopped moving, or is moving at very low speed.

    I've created a ball class that is inherited from KActor, but I can't see any functions that will do this for me.

    Is there something I can check with a Tick function, but I suspect that would be expensive...

  2. #2
    Administrator
    Join Date
    Jun 2006
    Posts
    272

    Default

    Ticking a single actor in UnrealScript will be negligibly expensive.

    If you want to check whether a physics object has stopped moving, you can implement the actor event OnSleepRBPhysics(). However, you may not get the results you want - in some cases the ball may take a long time to go to sleep, even though it is hardly moving. I'd recommend testing the velocity of the ball in a tick or timer function instead.

    If you really need to optimize the check, I'd suggest using a timer rather than a tick function, and setting the timer interval on each check based on the current velocity and an estimate of when it might come to rest.

  3. #3
    MSgt. Shooter Person
    Join Date
    Nov 2009
    Posts
    45

    Default

    Quote Originally Posted by Steve Polge View Post
    Ticking a single actor in UnrealScript will be negligibly expensive.

    If you want to check whether a physics object has stopped moving, you can implement the actor event OnSleepRBPhysics(). However, you may not get the results you want - in some cases the ball may take a long time to go to sleep, even though it is hardly moving. I'd recommend testing the velocity of the ball in a tick or timer function instead.

    If you really need to optimize the check, I'd suggest using a timer rather than a tick function, and setting the timer interval on each check based on the current velocity and an estimate of when it might come to rest.
    Awesome - thanks muchly

  4. #4
    MSgt. Shooter Person
    Join Date
    Nov 2009
    Posts
    45

    Default

    Anyone know if there is a built in function for the magnitude of a vector? Would save a little bit of maths.

  5. #5
    MSgt. Shooter Person
    Join Date
    Nov 2009
    Posts
    45

    Default

    Ah - is VSize the magnitude?

    I'm testing for VSize of velocity being = 0 and it seems to be instantaneous - i.e. the ball now won't move.

    simulated function Tick(float DeltaTime)
    {
    if (bShotTaken)
    {
    if (VSize(Velocity) == 0)
    {
    Gotostate('AtRest');
    }
    }
    }

    Then AtRest does the following:

    state AtRest
    {
    Begin:
    StaticMeshComponent.SetRBLinearVelocity( Vect(0,0,0) );
    StaticMeshComponent.SetRBAngularVelocity( Vect(0,0,0) );
    bShotTaken=false;
    }


    Am I doing something wrong?
    Last edited by ninjabadger; 11-13-2009 at 06:55 PM.

  6. #6
    MSgt. Shooter Person
    Join Date
    Nov 2009
    Posts
    171
    Gamer IDs

    Gamertag: xXTheSpaceManXx

    Default

    Isn't it possible that your linear and angular velocities are applied on the first frame, it runs a tick and haven't appliced the actuall velocity yet (depends on Tick vs. Physics update order), the tick runs and since the Velocity is Zero, it will go into the rest state and remove the velocities.
    Maybe wait a while before you do the check, or a number for updates etc.

  7. #7
    MSgt. Shooter Person
    Join Date
    Nov 2009
    Posts
    45

    Default

    Quote Originally Posted by TheSpaceMan View Post
    Isn't it possible that your linear and angular velocities are applied on the first frame, it runs a tick and haven't appliced the actuall velocity yet (depends on Tick vs. Physics update order), the tick runs and since the Velocity is Zero, it will go into the rest state and remove the velocities.
    Maybe wait a while before you do the check, or a number for updates etc.
    Yeah - that's why I added the takenShot bool to make sure it was actually moving first. Maybe I should just try setting the bool a little later.

  8. #8
    MSgt. Shooter Person
    Join Date
    Nov 2009
    Posts
    45

    Default

    Heh - putting a small sleep in there worked

  9. #9
    Palace Guard

    Join Date
    Jun 2007
    Location
    Christchurch
    Posts
    3,514

    Default

    You could also use VSizeSq which is the same as VSize but without doing a square root. May not matter in performance in the grand scheme of things, but usually if you can avoid a square root, I'd recommend it.

  10. #10
    Veteran
    Join Date
    May 2007
    Location
    Above KillZ, Below StallZ
    Posts
    9,953

    Default

    You could also avoid checking it until after it's come into contact with something.

  11. #11
    MSgt. Shooter Person
    Join Date
    Nov 2009
    Posts
    45

    Default

    Quote Originally Posted by Blade[UG] View Post
    You could also avoid checking it until after it's come into contact with something.
    Yeah - very good point - will try doing that


 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Copyright ©2009-2011 Epic Games, Inc. All Rights Reserved.
Digital Point modules: Sphinx-based search vBulletin skin by CompletevB.com.