My shapes aren't rotating?

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
conman420
Prole
Posts: 33
Joined: Sun Aug 31, 2008 8:46 pm

My shapes aren't rotating?

Post by conman420 »

I'm working on a offroad racing/terrain game sort of thing, I've done the level editor and made the levels physical. But when I added the 'car' it didn't want to rotate when going up slopes, it just stayed level, is there something i have to do to allow bodies to rotate? Even if I manually do it with setSpin it does nothing.

Attached is what I am talking about.
Attachments
Roller.love
(69.21 KiB) Downloaded 193 times
User avatar
conman420
Prole
Posts: 33
Joined: Sun Aug 31, 2008 8:46 pm

Re: My shapes aren't rotating?

Post by conman420 »

Forgot to mention the game will start in the level editor you press 1 for straight 3 for slope up and 2 for slope down :)

Also press enter to toggle the level editor and load the car.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: My shapes aren't rotating?

Post by bartbes »

It does rotate here (when done manually), I've also added a collision function and added basic turn data.
However as you can see, it does turn, but way too much.
But as I haven't actually used the physics engine myself it's all I can do now.
It should be enough to get you started.

Hope it helps.
Attachments
Roller2.love
(69.27 KiB) Downloaded 179 times
User avatar
conman420
Prole
Posts: 33
Joined: Sun Aug 31, 2008 8:46 pm

Re: My shapes aren't rotating?

Post by conman420 »

Thanks for your help but I found out what was causing it, turned out an object needs a certain amount of mass to rotate :)

Here is a beta of the driving game I'm working on :D

At the moment the transitions are a little funny. :(

Which brings me onto a new question to all you mathematicians out there!

Image

In this image the yellow box is the cars body.

The 2 red circles are the wheels and the red crosses are where I want the wheels to be. I need to find the position of those 2 red crosses.

Code: Select all

function createplayer(velx, vely, x, y, ang)
	clearplayer()
	if not ply.car_bod then
		ply.car_bod = phys.newBody(world, x, y, 500)
	else
		ply.car_bod:setPosition(x,y)
	end
	ply.wheeldiam = 30
	ply.wheelimg = love.graphics.newImage("images/wheel.png")
	ply.whl1_bod = phys.newBody(world, x + 50, y, 300)
	ply.whl2_bod = phys.newBody(world, x - 50, y, 300)
	ply.whl1 = phys.newCircleShape(ply.whl1_bod, ply.wheeldiam)
	ply.whl2 = phys.newCircleShape(ply.whl2_bod, ply.wheeldiam)
	ply.whl1_bod:setAngularDamping( 2 )
	ply.whl2_bod:setAngularDamping( 2 )
	ply.whl1_bod:setMassFromShapes()
	ply.whl2_bod:setMassFromShapes()
	ply.car_rect = phys.newRectangleShape(ply.car_bod,0,0, 150, 10)
	ply.car_bod:setAngle(ang)
	--ply.car_rect2 = phys.newRectangleShape(ply.car_bod,0,-30, 40, 50,00)
	ply.car_bod:setMassFromShapes()
	ply.jnt1 = phys.newRevoluteJoint( ply.whl1_bod, ply.car_bod, ply.whl1_bod:getX(),ply.whl1_bod:getY() ) 
	ply.jnt2 = phys.newRevoluteJoint( ply.whl2_bod, ply.car_bod, ply.whl2_bod:getX(),ply.whl2_bod:getY() )
	ply.whl1:setFriction( 2 )
	ply.whl2:setFriction( 2 )
	ply.car_bod:setVelocity(velx, vely)
end
That is the code for creating the player. When a transition to the next slide happens. the thing is when yo set the angle to other than 0 the wheels dont follow they are positioned as if the body was at angle 0. I really need help with this I don't know enough about trig/vector math to get my head round it :(

Thanks.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 44 guests