Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / any Bike/Car physics Setup outhere?

Author
Message
haliop
User Banned
Posted: 2nd Mar 2014 21:29
im trying to figure out how to create a car or a bike with a physics setup attached so the wheels will bounce like effect like in a real motorcycle.. my problem is that i dont understand physics joints like what is the diffrence between them ?
maybe theres a sample code somewhere here that i dont know about.. |

thank you for your time.

The Zoq2
14
Years of Service
User Offline
Joined: 4th Nov 2009
Location: Linköping, Sweden
Posted: 2nd Mar 2014 22:33
http://www.iforce2d.net/b2dtut/introduction has some really good information about most things relating to box 2d.

Say ONE stupid thing and it ends up as a forum signature forever. - Neuro Fuzzy
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 3rd Mar 2014 08:40
you can imagination than all parts are made with small pieces of elastic.
i can show u a image later.
similar bridge builder.

AGK 108 (B)19 : Windows 8.1 Pro 64 Bit : AMD Radeon HD 6670
TrezSoft
AGK Tool Maker
11
Years of Service
User Offline
Joined: 8th Nov 2012
Location: UK
Posted: 3rd Mar 2014 23:44
Depends how complex you want to make it and how good you are at setting up joints etc. I created an importer for rube the box2d editor made by iforce2d T1 and T2.

http://forum.thegamecreators.com/?m=forum_view&t=209686&b=41

I have a sample of the rube truck online ( sorry its not AppGameKit as its an HTML5 example)

http://trezsoft.de/rubemonkeyignition01.html

iforce2d also have a bike sample https://www.iforce2d.net/rube/loaders/javascript/ select the bike sample from the combo box.

Stuart
easter bunny
11
Years of Service
User Offline
Joined: 20th Nov 2012
Playing: Dota 2
Posted: 4th Mar 2014 00:11
I used many of those resources when making Ryder, If you want, I can give you some help on setting it up. The main thing that got me is that when you make the Revolve joints around the bike body (for the wheels), you set them up in world coordinates (ie. they're not relative to the sprites)

haliop
User Banned
Posted: 4th Mar 2014 07:32
easter it will help alot of you show a sample
i use line joints and they are not so good....

easter bunny
11
Years of Service
User Offline
Joined: 20th Nov 2012
Playing: Dota 2
Posted: 4th Mar 2014 07:51
Sure, here's my spaghetti code:


Ha! see if you can figure that out

haliop
User Banned
Posted: 4th Mar 2014 08:01
Thank you So much will sit on it right now see if i can figure it out . thank you easter bunny.

haliop
User Banned
Posted: 4th Mar 2014 08:23
Easter, now im adding velocity changes to the body to make it move..
but sometimes it will flip the car and im stuck with my wheels upwards..

any suggestion on how to make the car gain speed without using SetSpritePhysicsVelocity ?

haliop
User Banned
Posted: 4th Mar 2014 08:28
TrezSoft
AGK Tool Maker
11
Years of Service
User Offline
Joined: 8th Nov 2012
Location: UK
Posted: 4th Mar 2014 09:19
Motors will probably not give you the effect you are looking for. You should just be able to apply angular velocity to the wheels (not the chassis).

SetSpritePhysicsAngularVelocity(iSpriteIndex,velocity#)

or

SetSpritePhysicsAngularImpulse( iSpriteIndex, impulse )

You will need to cap the velocity at some point else your vehicle is going to end up on its back a lot.

This may also be worth a read https://www.iforce2d.net/b2dtut/constant-speed

Personally I think you was on the right track using the line joint. AppGameKit does not have the new box2d wheel joint type but you can combine a Distance joint and a Line joint to get the same effect.

If you want to try this Create a distance joint and then create a line joint using the same parameters. This will give you the basic wheel suspension and the wheel rotation.
easter bunny
11
Years of Service
User Offline
Joined: 20th Nov 2012
Playing: Dota 2
Posted: 4th Mar 2014 09:34
I used motors for Ryder

haliop
User Banned
Posted: 4th Mar 2014 14:29
TrezSoft
AGK Tool Maker
11
Years of Service
User Offline
Joined: 8th Nov 2012
Location: UK
Posted: 4th Mar 2014 14:36
If you are using revolute joints you just need to turn the motor On and set the speed and force as required:

SetJointMotorOn( iJointIndex, speed, maxForce )
haliop
User Banned
Posted: 4th Mar 2014 14:40
using SetSpritePhysicsAngularVelocity will reach a velocity of 37 or -37 but i need it to be faster... so that might not do the trick or am i forgetting something ?

haliop
User Banned
Posted: 4th Mar 2014 14:52
also using motor will get to top 37 angular velocity which is pretty slow... hmm

TrezSoft
AGK Tool Maker
11
Years of Service
User Offline
Joined: 8th Nov 2012
Location: UK
Posted: 4th Mar 2014 15:03
I did not know it had a limit but that's 37 degrees rotation per time step at 60 or 30 steps per second that's pretty fast !. Check the Mass of your objects, double check gravity is set correctly and make sure you have enough force / torque. Also make sure you do not have the angular damping set too high as this may apply too much friction to the wheel rotation.
haliop
User Banned
Posted: 4th Mar 2014 20:29
im getting there , but still it seams very odd it cannot climb on simple obstacles like stairs where each stair is just 1 on 1 size..
sometimes it just seams like its just hanging there where both front and back wheel are at angular velocity of 10... so i must be missing something...
this is what i have to move the car

bj = back joint
fj = front joint

TrezSoft
AGK Tool Maker
11
Years of Service
User Offline
Joined: 8th Nov 2012
Location: UK
Posted: 4th Mar 2014 21:09
Hard to tell from your description any chance you can post the code or some images. Its sounds like you are have friction issues ! try adding a little friction to your wheel fixtures. You probably have circle fixtures for the wheels with no suspension and a simple square fixture block you are trying to climb over. Depends on how much stuff this vehicle is going to have to climb over but you probably need to add some some fixtures around the tyres to get some kind of grip and/or add wheel joints like I suggested using a line joint and a distant joint. Take a look at the bike example in the link below you can zoom in on the bike to see the wheel nobles on the rear tyre. Also look at the front wheel this is a line / distance joint creating the suspension.https://www.iforce2d.net/rube/loaders/javascript/ Take a look at the truck sample using the same link , this is more complex as its using soft body physics to simulate the tyres.
haliop
User Banned
Posted: 4th Mar 2014 21:39
i tried line and distance together and everything jumped around

this is the car setup i forgot to add it before



haliop
User Banned
Posted: 4th Mar 2014 21:42
btw i can see the tires you are talking about (bike sample) .. yeah i guess that will help , i will try to add them right now..

haliop
User Banned
Posted: 4th Mar 2014 22:16
car setup after adding little boxes on the wheels ..



but still the car isnt strong enough

TrezSoft
AGK Tool Maker
11
Years of Service
User Offline
Joined: 8th Nov 2012
Location: UK
Posted: 4th Mar 2014 22:17
Multiple joints tend to be hard to set up by hand that's why I changed over to using rube and created the importer for AGK. If you send me over the images I can create you a physics body with suspension etc but you will need to use the importer to create the body or translate all the parameters by hand. The line joint / Distance joint combo needs the anchor points and local axis in exactly the right position to work. Motor torque needs to be approx 20, Frequency 8 and Damping ratio 0.8. For the tyres i create a script in rube to create the bumps on the wheels but you could do the same sort of thing in AGK. Create the body of the wheel using a circle fixture and then add an addition fixture on the outside of the circle. Then duplicate the fixture around the circle fixture remembering to rotate it.
TrezSoft
AGK Tool Maker
11
Years of Service
User Offline
Joined: 8th Nov 2012
Location: UK
Posted: 4th Mar 2014 22:23
Sorry I keep saying fixtures but AppGameKit calls them shapes, add fixtures to create the bumps don't make lots of bodies and weld them together ( well you can do it that way but you may have other issues).

What happens if you increase the maxforce on the motor ? add a couple of zeros to test if that's the issue.
haliop
User Banned
Posted: 5th Mar 2014 07:08
i dont know what the problem is
ive added little fixtures to the wheel and welded them together
it works better now but not as much as i want

haliop
User Banned
Posted: 5th Mar 2014 07:14
Trez i dont have an image to it yet cause i don't know what kind of car or bike i want and i want to keep the possibilities open
can you write down all the attributes i need to change in order to get it to work?
such as friction/ damping/ etc..
i just need one to work and i'll keep going from there
thank you for your time.

easter bunny
11
Years of Service
User Offline
Joined: 20th Nov 2012
Playing: Dota 2
Posted: 5th Mar 2014 07:33 Edited at: 5th Mar 2014 07:34
Here's a working motorbike demo that I whipped together for you.

Create a new project (landscape)

Main.agc


Setup.agc


Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 5th Mar 2014 08:37
hmm, not finished but i had began an example with our code for test.


AGK 108 (B)19 : Windows 8.1 Pro 64 Bit : AMD Radeon HD 6670
haliop
User Banned
Posted: 6th Mar 2014 11:25
sorry about the delay..
i think that the major problem i had was with friction adding it a value of 5 is really making everything run better.

but i have encountered another problem
when i weld diffrent sprites using CreateWeldJoint they "welded" sprites will not always stay in place and sometimes move around
any other method using physics to place something on top of the other? or maybe i use weld not the right way , i will example code later.

TrezSoft
AGK Tool Maker
11
Years of Service
User Offline
Joined: 8th Nov 2012
Location: UK
Posted: 6th Mar 2014 11:31
Great to hear you have it working

If you need multiple bodies to create an object you are best to use multiple fixtures(Shapes)unless you need a joint for some reason.

Create you base shape and then add shapes as required AddSpriteShapeBox, AddSpriteShapePolygon etc to the same sprite.

Stuart
haliop
User Banned
Posted: 6th Mar 2014 13:10
aha! so this is how its done! thank you

haliop
User Banned
Posted: 7th Mar 2014 09:32
Thank you everyone i got it working flawlessly

Login to post a reply

Server time is: 2024-05-03 01:44:13
Your offset time is: 2024-05-03 01:44:13