FAQ  •  Register  •  Login

understanding velocity

Forum rules
This forum is for technical discussion only. If you are interested in gameplay or client-side issues, please post in Bitfighter Features.
<<

tazinator

Posts: 352

Joined: Fri Jul 05, 2013 7:35 pm

Post Thu Mar 20, 2014 11:55 pm

understanding velocity

  Code:
bot:setVel(pt vel)

Sets the item's velocity.

As with other functions that take a point as an input, you can also specify the x and y components as numeric arguments.

Parameters
vel A point representing item's velocity.

Confusing to me. This point can't just be (x, y) because the bot will not work if that was the case. you can't just getPos and put that value in. I don't know what goes on with velocity...


working code: why is my ship faster?
  Code:
function onTick()
    table.clear(items)
    targetShip = findClosest(findAllObjects(items, ObjType.Ship))
    if(targetShip ~= nil) then
    local targetShiploc = targetShip:getPos()
    local angle = targetShip:getAngle()
    local playerVel = targetShip:getVel()
    if(bot:canSeePoint(targetShiploc)) then
        bot:setVel(playerVel)
        --experimental velocity code above. Why is my ship faster?
        --you can also do bot:setVel(2*playerVel) multiplying speed
        --TAZ
        --the following line is a pt, right?
        --bot:setVel(targetShiploc)
        bot:setAngle(angle)
        bot:fireWeapon(Weapon.Phaser)
        else
        bot:setAngle(angle)
        end
    end
end

 
Play my new level! Two different teams fight over a nexus: One mainly defends while the other attacks! is fun
viewtopic.php?f=33&p=21002#p21002
<<

watusimoto

Site Admin

Posts: 1558

Joined: Tue Feb 23, 2010 7:07 pm

Location: Quartz's mom's house

Post Fri Mar 21, 2014 1:42 am

Re: understanding velocity

I don't know the answer to your question, but you can see what velocity is by printing it using either logprint or, I think, print. Printed output is visible on the game console (ctrl-/).

I don't have the code in front of me, but I do believe that the velocity should sum to 1 (i.e. sqrt(x^2 + y^2) = 1), and that 1 represents full speed.
<<

tazinator

Posts: 352

Joined: Fri Jul 05, 2013 7:35 pm

Post Fri Mar 21, 2014 2:06 am

Re: understanding velocity

I'm not so good at math anymore..

But what you said sounds wrong.. sqrt is square root?
sqrt(x^2 + y^2) = 1


if x = 10 and y = 5
then x^2 + y^2 = 10^2 + 5^2 = 100 + 25 = 125
sqrt of 125 ≠ 1
if ^'s multiplication, not squaring
10x2 + 5x2 = 20 + 10 = 30
sqrt of 30 ≠ 1


I probably won't understand it, but maybe I will.
p.s. How do I get the table to print in console? it only shows me if something fails :D
Play my new level! Two different teams fight over a nexus: One mainly defends while the other attacks! is fun
viewtopic.php?f=33&p=21002#p21002
<<

bobdaduck

User avatar

Global Moderator

Posts: 790

Joined: Thu Mar 11, 2010 1:39 pm

Location: Utah

Post Fri Mar 21, 2014 7:53 am

Re: understanding velocity

You pass in a point value.

The X value of the point is the ships X velocity.
The Y value of the point is the ships Y velocity.

local vel = blah:getVel()
blahItem:setVel(vel)

blahItem:setVel(point.new(50, 50))

local blahItemVel = blah:getVel()
blahItem:setVel(blahItemVel.x + 50, blahItemVel.y + 50)
logprint("hello world! Your vel is " .. blahItem:getVel())
Little_Apple wrote:DnD: the REAL bitfighter levelgen documentation

Santiago ZAP wrote:bob doesn't make new maps, he makes new gamemodes
<<

watusimoto

Site Admin

Posts: 1558

Joined: Tue Feb 23, 2010 7:07 pm

Location: Quartz's mom's house

Post Sat Mar 22, 2014 11:59 am

Re: understanding velocity

What I meant was that I thought the total length of the moves added up to 1. That is, if you have c^2 = a^2 + b^2, and c was the length of your move, and a and b are x and y respectively, the total length would be 1.

I looked at the code just now, and it's not obvious that I am correct. I may be, but I may not be.

I thought (and still sort of think) that if you set your move.x to 100 and your move.y to 100, they will both get reduced to sqrt(2)/2, ~.707. I don't think you'll go 100x normal speed.
<<

tazinator

Posts: 352

Joined: Fri Jul 05, 2013 7:35 pm

Post Tue Mar 25, 2014 1:27 am

Re: understanding velocity

I still have no idea what's going on in velocity, then. :D
local targetShiploc
bot:setVel(point.new(targetShiploc))
bot:setVel(1.5(playerVel))

playerVel is defined earlier as
targetShip:getVel()

The first is funky, because it is missing speed.
The second is velocity working right.

anyway, I'd like to share that

MoveObject::setVel ( point vel )

mislead me. It makes me think I can just do
  Code:
bot:setVel(x, y)


wrong.

BobdaDuck, I did a logprint, and yep, getVel printing velocity gives you an (x, y) value. But setting velocity to an (x, y) value is seen to simply crash.
Play my new level! Two different teams fight over a nexus: One mainly defends while the other attacks! is fun
viewtopic.php?f=33&p=21002#p21002
<<

tazinator

Posts: 352

Joined: Fri Jul 05, 2013 7:35 pm

Post Tue Mar 25, 2014 1:42 am

Re: understanding velocity

also bobdaduck, using your velocity example crashed bitfighter

  Code:
   local botVel = bot:getVel()
        bot:setVel(botVel.x + 50, botVel.y + 50)
Play my new level! Two different teams fight over a nexus: One mainly defends while the other attacks! is fun
viewtopic.php?f=33&p=21002#p21002
<<

bobdaduck

User avatar

Global Moderator

Posts: 790

Joined: Thu Mar 11, 2010 1:39 pm

Location: Utah

Post Tue Mar 25, 2014 8:14 am

Re: understanding velocity

Oops, that's because you have to use point.new() any time you're using a point.

local vel = blah:getVel()
blahItem:setVel(vel) --this works because getVel() gets as a point value

blahItem:setVel(point.new(50, 50)) --Passing in a point like this requires point.new()
Little_Apple wrote:DnD: the REAL bitfighter levelgen documentation

Santiago ZAP wrote:bob doesn't make new maps, he makes new gamemodes

Return to Technical Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron