Sign in to follow this  
Followers 0
XZ3R0

Motion Tracking and velocity

9 posts in this topic

In short: how can i find the velocity of an object? Right now i have 2 pixelseraches that i plug into the formula of velocity. But once i run the second search the first one gets forgotten. So whats a work around or another way to find the velocity of an object.

Another problem i thought about is if the pixelsearch doesn't find the same object the second time. this would return with unusable data.

In long: i have an array of 3 colors im searching for. I run the first pixel search. lets say it finds black. then i runs a second pixlesearch. it also finds the same black. then i get the velocity and i do what i need with it. that's my theory. but what if during the second pixelsearch it finds red instead (a different object) then the formula isn't going to work. is there a way to track an object? or even search around the same area as before but for the same color? do i need to set the returned values for the pixlesearch in an array? or should i be using something completely different?

Share this post


Link to post
Share on other sites



"But once i run the second search the first one gets forgotten."

Using the same var?


[font="Verdana"]In work:[list=1][*]InstallIt[*]New version of SpaceWar[/list] [/font]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

no. one is $search = pixelsearch(...) and the other one is $search2 = pixelsearch(...)

then if i used $search[0] the script will run into an error and say something about a non arrayed variable trying to be use as a array.

Edited by XZ3R0

Share this post


Link to post
Share on other sites

Just seems like the first one does not find anything.

Try to check it with IsArray() or UBound() (IsArray would be better in this case)


[font="Verdana"]In work:[list=1][*]InstallIt[*]New version of SpaceWar[/list] [/font]

Share this post


Link to post
Share on other sites

the second one only runs if not @error. i do not get the error until AFTER the second one is ran.

Share this post


Link to post
Share on other sites

It would be easier with you posting a sample source....


[font="Verdana"]In work:[list=1][*]InstallIt[*]New version of SpaceWar[/list] [/font]

Share this post


Link to post
Share on other sites

$coor1 = PixelSearch( $start[0], $start[1], $current[0], $current[1], $Colors, 5, 8 )
            While Not @error
                $time = TimerInit()
                $coor2 = PixelSearch( $start[0], $start[1], $current[0], $current[1], $Colors, 5, 8 )
                $velocityx = ($coor1[0] - $coor2[0])/TimerDiff($time)
                $velocityy = ($coor1[1] - $coor2[1])/TimerDiff($time)
                MouseClick ( "left", (($velocityx*timerdiff($time))+400), (($velocityy*TimerDiff($time))+470), 1, 3 )
                Sleep(500)

Share this post


Link to post
Share on other sites

$coor1 = PixelSearch( $start[0], $start[1], $current[0], $current[1], $Colors, 5, 8 )
            While Not @error
                $time = TimerInit()
                $coor2 = PixelSearch( $start[0], $start[1], $current[0], $current[1], $Colors, 5, 8 )
                if IsArray($coor1) And IsArray($coor2) Then
                    $velocityx = ($coor1[0] - $coor2[0])/TimerDiff($time)
                    $velocityy = ($coor1[1] - $coor2[1])/TimerDiff($time)
                    MouseClick ( "left", (($velocityx*timerdiff($time))+400), (($velocityy*TimerDiff($time))+470), 1, 3 )
                EndIf
                Sleep(500)

Try this


[font="Verdana"]In work:[list=1][*]InstallIt[*]New version of SpaceWar[/list] [/font]

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

so it works now but the velocity thing doesn't. probably because the objects are restricted to a box or something :\

edit:

ok, my velocity formula was backwards should be coord2-coord1 but it still doesn't work.

Edited by XZ3R0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0