[SOLVED] love.physics - only change x velocity

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
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

[SOLVED] love.physics - only change x velocity

Post by Doctory »

I'm making a game where I use love.physics and I only want to change the x velocity instead of both x and y.
In a normal physics game where you change both velocities it would go something like this:

Code: Select all

body:setLinearVelocity(100, 100)
But for my game I only need to change the x velocity and not both. I tried doing body:setLinearVelocity(100, body:getLinearVelocity) and it just made it float when moving in a straight line.

Is there a way to only change the x velocity instead of both? Thanks in advance
Last edited by Doctory on Wed Jun 08, 2016 7:31 pm, edited 1 time in total.
User avatar
Beelz
Party member
Posts: 234
Joined: Thu Sep 24, 2015 1:05 pm
Location: New York, USA
Contact:

Re: love.physics - only change x velocity

Post by Beelz »

I think what you may want is applyForce(for constant "thrust") or applyLinearImpulse(for a nudge). This will append the current velocity.

Code: Select all

if self:hasBeer() then self:drink()
else self:getBeer() end
GitHub -- Website
User avatar
ArchAngel075
Party member
Posts: 319
Joined: Mon Jun 24, 2013 5:16 am

Re: love.physics - only change x velocity

Post by ArchAngel075 »

body:setLinearVelocity(100, body:getLinearVelocity() )

should work but body:getLinearVelocity() returns two values : x,y
so you would want to do

Code: Select all

	xNow,yNow = body:getLinearVelocity()
	body:setLinearVelocity(100, yNow ), 
else i have no clue.


-
Disclaim : I have not touched LUA/Love2d in months. excuse syntax errors please
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

Re: love.physics - only change x velocity

Post by Doctory »

ArchAngel075 wrote:-snip-
That worked! Thanks a lot!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Semrush [Bot] and 63 guests