Having a problem

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Kuromeku
Party member
Posts: 166
Joined: Sun Jul 20, 2008 5:45 pm

Having a problem

Post by Kuromeku »

When I do:

self:setVelocity( self:getVelocity() + envy.vector:new(16, 0) );

it doesn't apply gravity still, so the ball just moves to the right, I'd like it to still apply gravity.

and before you say, I've tried: self:setVelocity( self:getVelocity() + envy.vector:new(16, 16) ); or something similiar and it turns out really shitty.
User avatar
Kaze
Party member
Posts: 189
Joined: Sat Jul 19, 2008 4:39 pm
Location: Dublin, Ireland

Re: Having a problem

Post by Kaze »

Same goes for me. Changing the velocity removes some gravity apparently.
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Having a problem

Post by rude »

I don't know what kind of horrible things setVelocity does, but I guess you could use applyForce to apply the same force as gravity?
User avatar
cag
Citizen
Posts: 65
Joined: Sun Jun 29, 2008 5:09 am

Re: Having a problem

Post by cag »

Setting velocity changes the instantaneous velocity of the body in respect to the frame of reference of the world, so if you tell the object to have a velocity of (16, 0), it will at that very instance have that velocity. If you want the object to retain the downward velocity it has already gained from gravitational acceleration, you're gonna have to preserve the gravitational velocity while adjusting the horizontal velocity.

Also, from PIL: "Lua always adjusts the number of results from a function to the circumstances of the call. When we call a function as a statement, Lua discards all of its results. When we use a call as an expression, Lua keeps only the first result."

So when you do

Code: Select all

self:setVelocity( self:getVelocity() + envy.vector:new(16, 0) );
you're actually discarding the vertical component of the original vector.

Suggested:

Code: Select all

vx, vy = self:getVelocity()
self:setVelocity(vx + 16, vy)
User avatar
Kuromeku
Party member
Posts: 166
Joined: Sun Jul 20, 2008 5:45 pm

Re: Having a problem

Post by Kuromeku »

No, I'm not discarding it.

entity:setVelocity is a function I made that looks like this:

Code: Select all

function entity:setVelocity(velocity)
    self.b_Body:setVelocity(velocity.x, velocity.y);
end;
Where 'velocity' is a vector created with kudoLib's vector library. That is why when you see:

Code: Select all

entity:getVelocity() + envy.vector:new(16, 0)
It actually adds it to it, retaining the previous vertical velocity.

Thank you for your input however.
User avatar
cag
Citizen
Posts: 65
Joined: Sun Jun 29, 2008 5:09 am

Re: Having a problem

Post by cag »

Huh. That's weird.
Well, you can always apply impulse (mass * change in velocity).
User avatar
Kuromeku
Party member
Posts: 166
Joined: Sun Jul 20, 2008 5:45 pm

Re: Having a problem

Post by Kuromeku »

It is not wierd, it is handy. You should check out my vector library - it is so much easier working with vectors because you can easily add them, multiply them, or whatever.
User avatar
cag
Citizen
Posts: 65
Joined: Sun Jun 29, 2008 5:09 am

Re: Having a problem

Post by cag »

I meant that your code should work as intended, and that applying impulse instead of messing with velocity directly may solve the ball's problem.
Post Reply

Who is online

Users browsing this forum: 101Corp and 3 guests