anglerVelocity Affects linearVelocity

Hello. A while a go I started multiplying a physics body’s linearVelocity to give it a “boost” in its current vector. But this started doing some strange things like sending the ball speeding off its current course in directions that were far from its previous. After a bit of investigation I drew a parallel between these strange “boosts” and its angularVelocity. By setting the angularVelocity to zero after I “boost” it, the problems stop.

Does anyone know why this happens? The program below demonstrates this. Touching the screen will boost the ball. The parameter turns on and off wether it sets the angular velo to 0 after it boosts it. On is when it does zero the velo and off is when it doesnt.

-- Boost
function setup()
    parameter.boolean("angleBool", 0)
    oldAngleBool = angleBool
    ball = Ball()

    wallLeft = physics.body(EDGE, vec2(0,0), vec2(0, HEIGHT))
    wallBot = physics.body(EDGE, vec2(WIDTH, 0), vec2(0,0))
    wallTop = physics.body(EDGE, vec2(0,HEIGHT), vec2(WIDTH, HEIGHT))
    wallRight = physics.body(EDGE, vec2(WIDTH, 0), vec2(WIDTH, HEIGHT))

function draw()
    background(40, 40, 50)
    if oldAngleBool ~= angleBool then
        oldAngleBool = angleBool  


function GetAngleBool()
    return angleBool

function touched(touch)

Ball = class()

function Ball:init()
    self.ball = physics.body(CIRCLE, 50)
    self.ball.restitution = .6
    self.ball.x = 50
    self.ball.y = 50
    self.ball.gravityScale = 0
    self.ball.linearVelocity = vec2(10,5)
    self.angleBool = GetAngleBool()

function Ball:draw()
    fill(239, 12, 12, 255)
    ellipse(self.ball.x, self.ball.y, 100)

function Ball:Boost()
    if self.angleBool == true then
        print("self.ball.angularVelocity = 0")
        self.ball.angularVelocity = 0
    local bv = self.ball:getLinearVelocityFromWorldPoint(vec2(1,1))  
    local multi = 1.3
    local newVelo = bv * multi
    self.ball.linearVelocity = newVelo


function Ball:SetAngleBool(bool)
    self.angleBool = bool

try local bv = self.ball.linearVelocity

I’ve never needed to use getLinearVelocityFromWorldPoint, I never even knew it existed. Also try to have multi at a value around 1.05

@Goatboy76 Why are you getting the linearVelocity at point (1,1). What you need to do is get the linearVelocity of where the ball currently is. Try your code after changing the original line with the two lines I show. @Luatee That’s the suggestion I gave him when he posted something similar back on May 9th. See the link.

Link to similar post.

Original code plus the corrections.

    local bv = self.ball:getLinearVelocityFromWorldPoint(vec2(1,1))  

    local wp=self.ball.position   -- get current position of ball
    local bv = self.ball:getLinearVelocityFromWorldPoint(wp)  -- get velocity at point wp

@Goatboy76 After further investigation, “getLinearVelocityFromWorldPoint” gets the velocity of a point on the body in question. My example gets the linear velocity of the center point of the body, so the center point is unaffected by any angular rotation. In your example, you’re getting the linear velocity of a point (1,1) on that body. So if the center of the ball is at (100,100) then you’re getting the velocity of a point at a distance of 99 pixels away from the center. So depending on the angular velocity and the position of the ball on the screen, your linear velocity can vary quite a bit. That will explain why the ball shoots off the screen at a high rate or changes direction. So from the info I have, “getLinearVelocityFromWorldPoint” and “angularVelocity” are working the way they’re supposed to.

@dave1707 Thanks for the help. I suspected somehting was funky with getLinearVelocity from world point. So is self.ball.linearVelocity the same as getLinearVelocityFromWorldPoint(pos.x,pos.y)?

@Goatboy76 Yes.