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.

Code Snippets / [DBP] more realistic car movements

Author
Message
Blobby 101
18
Years of Service
User Offline
Joined: 17th Jun 2006
Location: England, UK
Posted: 3rd Mar 2007 13:27 Edited at: 3rd Mar 2007 20:56
this code is deigned to make a realistic car movement.



Projects: zlugs-2%
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 3rd Mar 2007 16:20
Realistic?

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Milkman
18
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 3rd Mar 2007 20:00
I don't think anything that's 12 lines can be realistic.

Who needs a signature?
Blobby 101
18
Years of Service
User Offline
Joined: 17th Jun 2006
Location: England, UK
Posted: 3rd Mar 2007 20:14
it's more realistic than having it just come to an instant stop when you let go of the button. it accelerates and slows to a stop. i just realized the code i posted was an old version. I've posted the working version now.


Projects: zlugs-2%
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 4th Mar 2007 06:18
Download the Newton physics library with walabers wrapper, that would be considered more realistic .

Blobby 101
18
Years of Service
User Offline
Joined: 17th Jun 2006
Location: England, UK
Posted: 4th Mar 2007 08:28
yeah, thanks but i like to find out how to do these things myself and then if i can't do it I'll download something to help me. i know this'll help some newbies. i would have put it in codebase but i wanted to hear what people thought of how it looks when compiled.


Projects: zlugs-2%
Blobby 101
18
Years of Service
User Offline
Joined: 17th Jun 2006
Location: England, UK
Posted: 6th Mar 2007 17:07
can i at least have someones opinion about what the result of compiling the code looks like. what people think about the way the car/cube moves.


Projects: zlugs-2%
Twu Kai
19
Years of Service
User Offline
Joined: 2nd Oct 2005
Location:
Posted: 6th Mar 2007 17:49
I like the smoothness of it. When I did something like that I used more than one variable, but you did it with one! I think it'll come in useful when making the movement of anything smoother, and with some more stuff it could be a lot like a car. Maybe as you're slowing down, the car could tilt forward a bit, and if you're turning left, then it could tilt right a bit. You get the idea.

Morwdnil
Blobby 101
18
Years of Service
User Offline
Joined: 17th Jun 2006
Location: England, UK
Posted: 6th Mar 2007 18:55
ok thanks! i'm working on a version where the turns at a differing speed depending on hoe fast it's going. i like the tilt idea.


Projects: zlugs-2%
Twu Kai
19
Years of Service
User Offline
Joined: 2nd Oct 2005
Location:
Posted: 6th Mar 2007 19:20 Edited at: 6th Mar 2007 19:21
I like the sound of the turning. If I get it right, the faster you go, the quicker you turn? That'd be good, because then you couldn't turn on the spot. Glad you like the tilting idea. Are you going to eventually make a racing game/car game of some sort from this? I look forward to a new version!

-Twu Kai
Blobby 101
18
Years of Service
User Offline
Joined: 17th Jun 2006
Location: England, UK
Posted: 6th Mar 2007 21:06
glad you like the idea. yeah it was the plan to make a racing game using this. though i don't know how far I'll get, ai seems to be a problem just waiting to happen and cameras are another thing that always seems a bit messed up in dbpro.


Projects: zlugs-2%
Twu Kai
19
Years of Service
User Offline
Joined: 2nd Oct 2005
Location:
Posted: 6th Mar 2007 21:18
Well, I know you can use the "Set camera to follow" command. It works quite well. The only thing is: If you're going to have the object it follows turn, you can't use the "Turn object left/right" command, as the camera seems to go to 180 degrees, then double back. You'll need to use the "yrotate object" commands.

Well, when you've got the core of the game working, you could try a straight racing track to get some simple AI up. Maybe even just start by pointing the car at the end mark, and moving the car towards it.

How's the coding going on the turning?

-Twu Kai
Blobby 101
18
Years of Service
User Offline
Joined: 17th Jun 2006
Location: England, UK
Posted: 6th Mar 2007 22:36
cool, i never knew about the set camera to follow command. about the turning, well it's going. slowly. but it's going. i've got two working methods of doing the turning going so i'm trying to find a sort of mid-point between the two.


Projects: zlugs-2%
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 7th Mar 2007 10:14
@blobby

Hello,

Not bad! I would suggest you create a condition to test for whether or not the car is moving (if speed <> 0) and allow turning only if that condition is true. A car can't turn if it's not moving.

Also, you might want to manually control your screen refresh with sync. It makes the example much smoother:



Enjoy your day.
Blobby 101
18
Years of Service
User Offline
Joined: 17th Jun 2006
Location: England, UK
Posted: 7th Mar 2007 18:28
hi, thanks for changing the code, it really helps. and as for that turning thing, as i said in previous posts, i'm working on it right now.


Projects: zlugs-2%
Green7
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: Switzerland
Posted: 19th Mar 2007 00:06 Edited at: 21st Mar 2007 22:01
@blobby:

i looked at your code, tested it and had a lot of fun building from this basic structure. look at what happened to your code and have fun, i hope it would help you. i did not comment the changes, if you got questions just ask. it is surely not perfect, but for me as i did this for the fist time, i'm happy with it.



Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 19th Mar 2007 01:51 Edited at: 19th Mar 2007 01:52
@Green7: Nice car! I added extremely annoying car sounds to the mix BEWARE OF MOVING!



Blobby 101
18
Years of Service
User Offline
Joined: 17th Jun 2006
Location: England, UK
Posted: 19th Mar 2007 18:52
that's cool!
can i just ask, in that code which object number is the floor?
i'm trying to implement my gravity code.


Projects: zlugs-2%
el zilcho
17
Years of Service
User Offline
Joined: 4th Dec 2006
Location:
Posted: 19th Mar 2007 20:07
its object 50.

btw, the car's wheels should always turn right when you press right, and vica versa.

so the car would actually turn the other way when reversing.

-EZ-
Green7
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: Switzerland
Posted: 19th Mar 2007 21:08 Edited at: 21st Mar 2007 22:01
@ blobby:
i once made a gravity code that makes a car stay on a *.x file, tilting on slopes correctly. if youre intressted i can look for it and post it.


@el zilcho:
they do... or didn't i understand what you mean?

Blobby 101
18
Years of Service
User Offline
Joined: 17th Jun 2006
Location: England, UK
Posted: 19th Mar 2007 21:16 Edited at: 22nd Mar 2007 10:10
@green7: can you post that? it sounds interesting.


thanks to deathead for the sig!
Projects: zlugs-2%
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 25th Mar 2007 02:53
hello everybody

another car between mountains . Don´t forget to hide litle balls



oh my god
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 25th Mar 2007 03:54 Edited at: 25th Mar 2007 03:54
@hafari: It's cool, but it doesn't use Blobby's method at all

Ankillito
17
Years of Service
User Offline
Joined: 10th Dec 2006
Location: Litigious California
Posted: 25th Mar 2007 19:34 Edited at: 26th Mar 2007 07:06
Talk about irony, we completely forgot of the original thread.

"There will always be evil, for, without evil, the good shall lose their virtue."
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 27th Mar 2007 21:50
Here's some math too help you with the turning:

To find the angle matching the current speed and the center of the circle where the car should turn around:

dist# = 5.0
speed# = well, speed

the basic formula would be
arc (speed#) = 2*pi*dist# * (angle / 360)

so with a little math magic:
angle = (180 * speed#) / (pi * dist#)
(If i didn't make a mistake)

Basically that would mean:


After that, you can calculate the forces caused by turning, and let it get loose from the ground when it gets too high...

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 1st Apr 2007 22:22
Hmmm. I should try that sometime, Sven. Here is your equation for the arc in a function. It can't generate a runtime error:



Blobby 101
18
Years of Service
User Offline
Joined: 17th Jun 2006
Location: England, UK
Posted: 1st Apr 2007 23:25
thanx all, i think i will leave the code as it is for the time being. fell free anyone else to update it.


thanks to deathead for the sig!
Projects: alien abductor-5%
Dabbler
17
Years of Service
User Offline
Joined: 3rd Mar 2007
Location: Minnesota
Posted: 5th Apr 2007 06:35
Oh no blobby 101, you started this.

Check the pic. Your movement has been built into this.

Well, mabey reverse and wheel movement may have been added by me.

I cannot thank you and all others on this site for help enough.


Whatever...

Attachments

Login to view attachments
Blobby 101
18
Years of Service
User Offline
Joined: 17th Jun 2006
Location: England, UK
Posted: 5th Apr 2007 21:48
is that a game your making? it looks cool!
and i see your driving that car at full speed, good on you!


thanks to deathead for the sig!
Projects: alien abductor-5%
Dabbler
17
Years of Service
User Offline
Joined: 3rd Mar 2007
Location: Minnesota
Posted: 5th Apr 2007 21:55
It is not a game yet. I only have a rough idea and I am building some components.

I hope to make it into a game when I get the time.

Thanks again.


Whatever...
Aaron Miller
18
Years of Service
User Offline
Joined: 25th Feb 2006
Playing: osu!
Posted: 12th Apr 2007 07:09
Quote: "3.141592654"

Pi is 3.141592653.

Cheers,

-db


Albert Einstein believed that imagination is more important than knowledge.
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 12th Apr 2007 19:27
Quote: "Pi is 3.141592653"


nope, the next number of pi is 3.1415926535 which means you have to round up to 3.141592654...

For some more numbers, I believe there was a thread about it once in code snippets lol...

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Dabbler
17
Years of Service
User Offline
Joined: 3rd Mar 2007
Location: Minnesota
Posted: 13th Apr 2007 05:14
I am just wondering how much differance that makes if your vehicle is 10 units long?


Whatever...
Blobby 101
18
Years of Service
User Offline
Joined: 17th Jun 2006
Location: England, UK
Posted: 7th Jun 2007 20:27
@green7: can you look for that gravity code please, it would be very useful.


thanks to deathead for the sig!
Projects: alien abductor-5%
Green7
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: Switzerland
Posted: 12th Jun 2007 21:35 Edited at: 12th Jun 2007 21:48
oh, sorry, i forgot about it...

maybe you have to make a "pivot object" for example a cube. this object does all the tilting and grinding on the ground. then you can set your car or what ever to the values of the pivot object. dunno, you have to test, cause i had some issues as i had a rotating guntower on top of it.

this is the function for an object to stay on top of a *.x level without tilting



here the tilting function. id is for the object number you want to tilt. it worked for me, but maybe you have to fiddle around with a pivot object, as i said.



jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 14th Jun 2007 00:33
Nice Thread. I appreciate the math for turning radius velocity. I'll certainly use that in my project (though flying, same principle)

The thread (to recap) was more or less - Real Car Physics Code Example, and there was a comment about using newton physics dll versus the home grown "sorta physics" code I'm personally fond of (application dependant of course): if for no other reason than the challenge of trying to mimic behaviors (of anything for that matter) in code/gfx.

I've personally seen a few newton.dll demos - and frankly they are so slow they stink... Even the one from the Newton.dll's web site. Admittedly this could be the programmers and not the DLL.

I did see ONE demo that seemed reasonsable speed wise - but that was a rather naked demo. Yes there was a track, under a roof - and a red car - but that was it. I can imagine it beginning to crawl as things like cool tire turning GFX/animations added, AI cars, more sounds and background eye candy...

so back to point - the code sample in the beginning of this post was clever and simple - and the feedback and code changes of everyone as a group was fun to read and examine.

Know way to many languages - Master of none
Kyhoshi
18
Years of Service
User Offline
Joined: 21st Jun 2006
Location: Somewhere over the rainbow.
Posted: 16th Jun 2007 09:08
okay, this is turning out very well, however, you all overlooked one thing, the POWERSLIDE if you reach a certain speed, then reverse, you will be whipped around. i didn't really feel like reading through the last like 5 comments, however, i did make a powerslide based on the original code. I must admit, though, i didn't have time to test it.


(\__/)
(O.o )
(> < ) This is Bunny. Copy Bunny into your signature to help him on his way to world domination!
Ankillito
17
Years of Service
User Offline
Joined: 10th Dec 2006
Location: Litigious California
Posted: 21st Jun 2007 08:21 Edited at: 21st Jun 2007 09:01
Ok, I was messing with chafari's code, trying to eliminate the spheres entirely and hopefully add jumping off ramps and rolling the vehicle.

Here's what I got:



However, I don't know why it insists on rolling down hill. It's a nice bug, but I need to slow it down. Well, it's a work in progress...

Updated:


Now the falling down hill is on purpose, and adjustable. See line 103. You can actually get air, but you can't tell from this view Plus, now it has a realistic gass pedal w/ upkey

"There will always be evil, for, without evil, the good shall lose their virtue."
Blobby 101
18
Years of Service
User Offline
Joined: 17th Jun 2006
Location: England, UK
Posted: 21st Jun 2007 09:23
thanks all!
BTW, does anyone here know why the subject title now has DBC at the beginning? the original code was made in dbpro.


thanks to deathead for the sig!
Projects: alien abductor-5%
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 21st Jun 2007 10:20
im guessing a moderator is trying to make the snippet titles more friendly and made a mistake with one.

jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 21st Jun 2007 13:46
I have been messing with a "Descent" like game with 6 degrees of movement - Strafe up, Strafe Down, Strafe Left, Strafe Right, plus rolls, turns, and foward, back flight movement.

Now I use the basic 3d commands for movement but I found that speed velocity for the SHIP's (not the wolrd's) X,Y,Z has helped.

The same priniciple you have here with speed increasing, and the slow down effect - I have applied to the ships's X,Y,Z.

When There is Input like a FORWARD key, I simply say: THRUST= 1. Nothing, thrust=0 and Thrust=-1 for reverse. Then I Add my Thrust amount to this velocity: inc VelocityZ, thrust * howmuch

And later in the loop I move "object ship, velocity"

If Thrust is ZERO - then I take some velocity off, if negative - well - same as forward (Cuz I like it going as fast backwards as forward.

If you add the Max Speed and min velocity limits - you can get all velocities working decently in preparation for some cheap physics I would think.

I think I'm implementing a simple "Vector" kind of thing - something I wish I understood better: Vectors and Normals I think might help us here.

Know way to many languages - Master of none
Blobby 101
18
Years of Service
User Offline
Joined: 17th Jun 2006
Location: England, UK
Posted: 21st Jun 2007 18:09
oh, that makes sense.
well, can the mod who did it change it to dbp please.


thanks to deathead for the sig!
Projects: alien abductor-5%
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 22nd Jun 2007 01:31
Indi is correct and by the time you read this, it will have been corrected!

All I can say is:

http://forum.thegamecreators.com/?m=forum_view&t=59409&b=6

It couldn't be any clearer really.

I may have made a mistake on a couple of them, (and probably will do on a few more in the future - assuming I don't get fed up with doing it and lock them instead), but if people read the stickies, editing post topics wouldn't be necessary...

TDK_Man

chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 2nd Jul 2007 01:12
wow !!Ankillito...it is really kool..ha ha...i like it...with the sliding like ice on floor, this code(your code)is usefull somehow...i,ll keep it for sure !!


cheerz.

oh my god
Ankillito
17
Years of Service
User Offline
Joined: 10th Dec 2006
Location: Litigious California
Posted: 7th Jul 2007 22:38
Thx! I tried to add AI, but it doesn't seem to like me right now...

"There will always be evil, for, without evil, the good shall lose their virtue."

Login to post a reply

Server time is: 2024-11-22 18:34:40
Your offset time is: 2024-11-22 18:34:40