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.
Having a problem
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Having a problem
Same goes for me. Changing the velocity removes some gravity apparently.
Re: Having a problem
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?
Re: Having a problem
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 doyou're actually discarding the vertical component of the original vector.
Suggested:
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) );
Suggested:
Code: Select all
vx, vy = self:getVelocity()
self:setVelocity(vx + 16, vy)
Re: Having a problem
No, I'm not discarding it.
entity:setVelocity is a function I made that looks like this:
Where 'velocity' is a vector created with kudoLib's vector library. That is why when you see:
It actually adds it to it, retaining the previous vertical velocity.
Thank you for your input however.
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;
Code: Select all
entity:getVelocity() + envy.vector:new(16, 0)
Thank you for your input however.
Re: Having a problem
Huh. That's weird.
Well, you can always apply impulse (mass * change in velocity).
Well, you can always apply impulse (mass * change in velocity).
Re: Having a problem
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.
Re: Having a problem
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.
Who is online
Users browsing this forum: Ahrefs [Bot] and 10 guests