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 / Side view 2D racer with Physics

Author
Message
Richard_6
7
Years of Service
User Offline
Joined: 3rd Feb 2017
Location:
Posted: 11th Feb 2017 23:56
Hey everyone!

I've been trying some 2D physics with a 2D racing game. I found some references here in the forum but using top down view but I'm working on a side-view.

I think I need to use torque, force and further evolve to scrolling with setviewoffset but after some unsuccessful trials, I came here to ask the experts

Anybody could give me a hint?

haliop_New
User Banned
Posted: 12th Feb 2017 06:50 Edited at: 12th Feb 2017 06:52
2d platform racing can be done with AppGameKit 2.0+
and yeah you'll need to

one or some sprites for the main vehicle
2 sprites for the wheels
create joints between the wheels and the vehicle sprite
I have already done this several times

then you apply force or torque (that I cannot remember) to one of the wheels
if you want to simulate 4x4 then apply to both wheels
if you want to simulate locked 4x4 then apply the same amount of torqu/force to both wheels

its kinda cool.
then with static sprites as your course , this is most definitely do able.

just remember to play with mass , friction, velocities as you will get different results.
you can also use SetSpriteAngularVelocity for the wheels you'll get different results but you may want that from time to time such as the 4x4 lock simulation.

hope to see something good

EDIT: also play with SetPhysicsScale, SetPhysicsGravity at startup and Update(###) in your main loop.
everything will play out different as you change values so you will have to find whats best for your game.
Richard_6
7
Years of Service
User Offline
Joined: 3rd Feb 2017
Location:
Posted: 12th Feb 2017 13:12
Thank you haliop, I'm trying some variations.
Do you have any example that you could share here?
haliop_New
User Banned
Posted: 12th Feb 2017 16:28
i cant sorry but i might build a new one for you if i'll have the time
it should not take long i'll try to come up with a demo now , give me an hour...
haliop_New
User Banned
Posted: 12th Feb 2017 17:04


its not perfect but it may get you started
i actually forgot how i did it the last time.
hopefully someone will fix this , but you'll get the hang of it dont worry.
i got caught in a mess with this code , it should be much more easier
the part where it is commented out is where you add the wheels little extra circles at its radius this is for better friction however it made my vehicle jump up and down...
Richard_6
7
Years of Service
User Offline
Joined: 3rd Feb 2017
Location:
Posted: 12th Feb 2017 17:48
Thank you!! Let me test it right now
Richard_6
7
Years of Service
User Offline
Joined: 3rd Feb 2017
Location:
Posted: 12th Feb 2017 19:20
As for now I just a car moving straight, I removed the angles and just added a SetSpritePhysicsTorque to see what happens. Even typing "9999999", the car is really slow and I haven't found many examples using the torque function. Any ideas?

CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 13th Feb 2017 00:16
You'll need to increase the friction of the wheels and the ground using setspritephysicsfriction. The docs suggest the range is between 0 and 1, but in my experience it is more like 0 and 2 (2 being completely un-slippy and 0 being ultra slippy).

When it comes to building your static object landscape, there's a tool called R.U.B.E which looks really great for positioning the physics shapes over your background image(s). I don't know who did it, but someone has even built an amazing AppGameKit exporter and loader for it!

Check this intro to RUBE. Looks super! I've never used it, but think I might one day. (11 mins in shows fitting physics shapes to a background image).



R.U.B.E: https://www.iforce2d.net/rube/

Here's the git for the AppGameKit loader
https://github.com/trezsoft/AGK-Rube-Loader
Richard_6
7
Years of Service
User Offline
Joined: 3rd Feb 2017
Location:
Posted: 13th Feb 2017 02:59 Edited at: 13th Feb 2017 03:01
Hi CJB. I increased the friction and still got the same speed.

R.U.B.E looks really cool. I will definitely try.

Thanks.
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 13th Feb 2017 11:52 Edited at: 13th Feb 2017 12:04
I just ordered RUBE... Still waiting for my download credentials... Will let you know how I get on with it.

... My download link arrived... They build a unique version per user. Building now...
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 13th Feb 2017 11:55
This should be really interesting as the clip looks awesome!!
The Amiga and Amos were great!
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 13th Feb 2017 12:17
Installed RUBE, loaded an example scene (truck), exported using the AppGameKit export script, and managed to load the scene into an AppGameKit project! I'll have a proper play with this tonight after work, but I'm kind of excited about this...
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 13th Feb 2017 12:52
Would be good to see a clip of something working if you can. Might purchase this myself if you think it's worth it.
The Amiga and Amos were great!
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 13th Feb 2017 15:41
Rube looks pretty handy.

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 13th Feb 2017 20:41
It looks very capable. This is AppGameKit running one of the example scenes from RUBE. I've made a little change to the truck whilst playing around (replaced the soft tyres with solid, so not as impressive looking as before - sorry! Lol)

Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 13th Feb 2017 21:02 Edited at: 13th Feb 2017 21:08
That looks really impressive!

Can you give some more info please?
Is it Tier1 or 2?
How much tinkering does it take to get the RUBE level imported?
How much code is needed to use it once it is imported?
Is there two way interaction? By that I mean do you have full control of everything in the imported RUDE level or is it simply playing what was created. Can you change the imported level? Can you get data back about what it going on in the level?

Thanks for being the guinea pig. Depending on your answers I may just buy this myself

[Edit] Just noticed that there is a trial version - downloading now. I might be able to answer my own questions soon
AGK V2 user - Tier 1 (mostly)
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 13th Feb 2017 22:55 Edited at: 13th Feb 2017 23:07
It's Tier 1!

Quote: " I might be able to answer my own questions soon"
Nah... I thought that. The trial version doesn't allow you to export anything. Shame. However, yes, you have full control over everything within AGK. It's just a bunch of physics sprites after all. The loader code from TrezSoft is really straightforward to use. Grab it from the GitHub link I posted above to see what's involved. It simply creates sprites and applies a whole bunch of physics parameters to them based on what was exported from RUBE. To load a scene is as simple as:

... the parameters are:


I don't know who Stuart Tresadern is, but why hasn't he made more of a big deal about this sweet bit of code? I don't think there's even a showcase for it. Nice work Stuart! THANK YOU!

It looks like there were a few features that weren't available when the export script was written (such as no output from RUBE for motor speed / torque or "joint collide connected"... but we can just code around those in the program).

When I first fired up the scene, nothing was happening so I thought I'd apply torque to the wheels when the mouse button is pressed - except I didn't know which objects were the wheels. A simple check with:

soon resolved that. Also, I think the object numbers probably match up with those in RUBE too (allowing for the offset given in the loadrubescene parameters), so all looking good so far!

[edit] ...sorry, forgot to add the code for that little example:
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 13th Feb 2017 23:04
Thanks for the info and thanks for the exporter Stuart - whoever you are
Tier 1 too? That's a surprise!
This really does look amazing, I can't believe it's been 'hidden' for so long.
I've already noticed how limiting the trial is, so I'm heading to the shop now
AGK V2 user - Tier 1 (mostly)
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 13th Feb 2017 23:10
Oh... I had to make a couple of tiny changes to the importer to get it to work... just to fix a couple of syntax errors (I think some brackets were in the wrong place - easy fix. Give me a shout if you need the repaired version).
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 13th Feb 2017 23:38
Just had a quick chat with Stuart on LinkedIn and he is TrezSoft on here

He has just mentioned about the thread for R.U.B.E which is here:

https://forum.thegamecreators.com/thread/209686


Cool things may be to come with updates. Heres hoping they will and very cool work TrezSoft!
The Amiga and Amos were great!
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 13th Feb 2017 23:59
Excellent! Yes indeed. Great work TrezSoft! This will be handy for building my Fruit Smoothie levels!


Richard_6
7
Years of Service
User Offline
Joined: 3rd Feb 2017
Location:
Posted: 14th Feb 2017 01:59
Really interesting!

How did you add the torque on RUBE CJB? I haven't found torque or power in the properties.

I know it's asking a lot but would be really cool if you could make a simple tutorial hehe, specially the importing stage.
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 14th Feb 2017 09:01
I added the torque in the AppGameKit code (the last code segment here). Whenever the mouse button is pressed, I apply torque to both wheels.

This was only an example to show how easy it is to import the scene into AGK. No need for a tutorial, the import is just one line of code!

TrezSoft
AGK Tool Maker
11
Years of Service
User Offline
Joined: 8th Nov 2012
Location: UK
Posted: 14th Feb 2017 14:05
Hi All,

Looks like the exporter and Importer are both a little out of date and the image support now fails.

Its been a long time since I looked at this but ill get it up to the latest versions for both RUBE and AppGameKit , maybe tempted to put a few tutorials together if there is enough interest.

Stuart
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 14th Feb 2017 14:50
Absolutely! That'd be fantastic. Thanks!
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 14th Feb 2017 15:48
Would be awesome as this looks invaluable for AGK. Great work and will keep my eye on this.

Cheers Stuart.
The Amiga and Amos were great!
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 14th Feb 2017 17:27
Great work TrezSoft, I can't believe I didn't see your original post.
This looks amazing so yes, I'm adding my interest to the list
AGK V2 user - Tier 1 (mostly)
TrezSoft
AGK Tool Maker
11
Years of Service
User Offline
Joined: 8th Nov 2012
Location: UK
Posted: 14th Feb 2017 18:45 Edited at: 14th Feb 2017 19:04
Anyone know what version of box 2d is used in AppGameKit 2 ?

Still seems to be an old version as the joint types are limited etc.

Can work around most of them but would be great if box 2d could be updated to give us access to the newer features.

Thanks

Stuart
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 14th Feb 2017 19:19
Not sure but have asked Rick on the Slack channel so see if he gets back to this thread
The Amiga and Amos were great!
TrezSoft
AGK Tool Maker
11
Years of Service
User Offline
Joined: 8th Nov 2012
Location: UK
Posted: 14th Feb 2017 20:44 Edited at: 14th Feb 2017 21:31
Wow super rusty , how do I convert an int to binary in AppGameKit , need it to get the collision masks working correctly .

Thanks

Stuart

**** PLEASE IGNORE ****, issue was in the export file, seems the SetSpriteCollideBits etc works with integer values
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 14th Feb 2017 21:40
Currently AppGameKit uses Box2D 2.2.0, I haven't kept up to date with the latest Box2D features, what is missing?
TrezSoft
AGK Tool Maker
11
Years of Service
User Offline
Joined: 8th Nov 2012
Location: UK
Posted: 14th Feb 2017 23:34
Hi Paul,

Biggest changes in 2.3.0

Polygon creation now computes the convex hull. Vertices no longer need to be ordered.
The convex hull code will merge vertices closer than dm_linearSlop. This may lead to failure on very small polygons.
Added b2MotorJoint.
Bug fixes.

Also seems like some joint types are not all implemented in AGK

Motor Joints
Friction Joints
Rope Joints
Wheel Joints
( can work around some of them using combinations of joints already in AGK)

I think the rest is just down to the way AppGameKit implements Box2d

You can not set Friction, Restitution, Density, Sensor, Filters (group,mask,category) per shape (fixture), ( wooden stick with rubber balls on the ends for example )
You can only assign a single image to the body, ideal would be to add images to the fixtures(shapes) also so that you can create composite sprites that move together.

All can be worked around with joints etc. , just makes it a lot harder to setup.

Thanks for letting me know the current box2d version.

Stuart


TrezSoft
AGK Tool Maker
11
Years of Service
User Offline
Joined: 8th Nov 2012
Location: UK
Posted: 14th Feb 2017 23:45
Hi,

Seems MadBit created a JSON module https://forum.thegamecreators.com/thread/218297 so it may be better for me to create a new version of the importer based on that as RUBE exports to JSON out of the box and does some cleaver stuff on the way , like splitting polys with more than 8 points into multiple fixtures ( shapes in agk). Currently you have to split them manually inside the RUBE editor which can take some time if you sample a complex image, as I can't do it within the Angel script I created to export the data.

I'll try and get the latest version online tomorrow which fixes a lot of the current issues while I take a look at a JSON version, already done a few for other engines with json so should be pretty quick.

Still trying to think of a better way to present the data from the importer to allow easier access to the generated sprites and physics objects , can be hard to find the one you want at the moment. Any input welcome. Suppose I could generate the code for objects on the fly !, can also pass in custom parameters set on physics bodies ( # lives for example )

Stuart
Richard_6
7
Years of Service
User Offline
Joined: 3rd Feb 2017
Location:
Posted: 15th Feb 2017 04:10
Sounds great TrezSoft. Looking forward to see it
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 15th Feb 2017 09:26
Please don't be tempted to make this into a game engine. I'd like to see this as a pure physics editor / importer that can be used for any genre... if it handles images too, great! but lives and such should be handled in AppGameKit by the programmer IMO.
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 15th Feb 2017 09:37
^What he said!
AGK V2 user - Tier 1 (mostly)
TrezSoft
AGK Tool Maker
11
Years of Service
User Offline
Joined: 8th Nov 2012
Location: UK
Posted: 15th Feb 2017 16:26
Hi,

No way is it going to be any type of game engine, no point as all games are different , just thinking about allowing you to bring in the custom params that can be set inside rube. Will be totally up to you if you use them or what they are.

Stuart
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 15th Feb 2017 17:09
Cool! In that case: Sounds good!
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 15th Feb 2017 17:12 Edited at: 15th Feb 2017 17:13
All sounding very good at the minute. Think R.U.B.E will get quite a few sales off the back of this.
The Amiga and Amos were great!

Login to post a reply

Server time is: 2024-03-29 10:16:14
Your offset time is: 2024-03-29 10:16:14