Hi !
Featured games (87)
games approved by the League of Dukes
Games in Showcase (670)
Games in Android Showcase (194)
games submitted by our members
Games in WIP (727)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  LibGDX - Car (Sprite) follows (or moves on) the way (path) and auto rotate?  (Read 6750 times)
0 Members and 1 Guest are viewing this topic.
Offline ddfh

Junior Devvie

Medals: 1

« Posted 2013-02-06 18:02:00 »


We have been trying since 6 days to solve this problem.  Sad

On the image you can see a car and a way. We want, that the car (sprite) follows (or moves on) this way (path) with autoRotate and constant speed.

We made this "way" with inkscape. We can save the "way" as .svg to get the path.
The car should follow the path and changing his direction with constant speed.

for example the .svg file:
   d="m 196.47467,414.45085 ... etc."
   inkscape:connector-curvature="0" />

The SVG path file is not important. We can also write our own path array.

We thought, that Path moving is so important for game developers. And we never thought, that this takes 6 days
at the beginning.

We can't find any good examples or tutorials.

Yes, it's true. We asked this question in another forum. But after 6 days, we need now a solution.
This is the forum where we asked the question:

We heard about tween engine by greensocket. There is a animation on the website. It's called "bezier example" and it's in the
TweenLite/Max Plugin Explorer.
We first thought. Great, but it's only for Flash and Javascript. We first thought to the change the JS code to java, but the
code is too much.

We are grateful for any help.

Online Jimmt
« League of Dukes »

JGO Kernel

Medals: 167
Projects: 5
Exp: 3 years

« Reply #1 - Posted 2013-02-06 18:04:28 »

If your track isn't overly complex, I suppose you could just set some "points" on the track on corners and whatnot, and then rotate the car vector to each point, and then accelerate. As the car passes that point, you could just have it vector rotate to the next point, and so on.
Offline cylab

JGO Wizard

Medals: 131

« Reply #2 - Posted 2013-02-06 22:01:48 »

Try tris code

- Construct a Spline with your path points (and optional control points)
- use samplePoint() to get two points from the spline a little bit before and a little bit after the desired car position
- create a vector pointing from one point to the other
- normalize it -> now you have a direction vector to use for your car rotation

The code is for 3D, so just use 0 as z component

Mathias - I Know What [you] Did Last Summer!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ClickerMonkey

JGO Coder

Medals: 20

Game Engineer

« Reply #3 - Posted 2013-02-07 05:18:05 »


That's some crazy ass code just for a cubic Bezier Curve...

Offline cylab

JGO Wizard

Medals: 131

« Reply #4 - Posted 2013-02-07 07:46:32 »

well... thanks  Tongue

Mathias - I Know What [you] Did Last Summer!
Offline ddfh

Junior Devvie

Medals: 1

« Reply #5 - Posted 2013-02-07 09:16:18 »

@cylab: Ok. We will look at this code.

EDIT: Are there some examples of how to use this code? And can we make a one round track like the first
picture above?
Offline Axeman

Senior Devvie

Medals: 7

« Reply #6 - Posted 2013-02-07 13:27:40 »

I did something like this just last week, even though it wasn´t cars. I set up a path of nodes for my game-enemy. Each node has a radius and when the enemy is within that radius he switches to the next node. This made him walk around in a perfect rectangle. Next thing I did was getting rid of the instant change in direction by implementing a seek behavior. This makes the turns smoother and more "realistic" looking. I think this would work out for you too: Set up a bunch of node in each turn. Implement a seek behavior that´s "seeking" for the next node/turn and then you should have a car that´s following a smooth path.

Here´s a link if you want to read about seek behavior (not java, but the concept is there):

ps. It should be noted that my enemies did not rotate, but that shouldn´t be to hard to work out...
Offline cylab

JGO Wizard

Medals: 131

« Reply #7 - Posted 2013-02-07 15:25:31 »

Are there some examples of how to use this code?

No, but just try what I described in my last post

And can we make a one round track like the first picture above?

Look up Cubic Bezier Splines - they are not closed paths. For a round track you have to set the first and the last base point to the same coordinates and set the control points to mirror at the basepoint.

You should be able to export a cubic b-spline from inkscape and use exported coordinates as base- and control-points. But since I never used inkscape, you have to google or ask in their forum.

Mathias - I Know What [you] Did Last Summer!
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

IanParcs (35 views)
2016-04-18 14:18:53

KaiHH (34 views)
2016-04-18 08:35:41

KaiHH (66 views)
2016-04-15 12:43:58

theagentd (64 views)
2016-04-14 02:16:17

theagentd (72 views)
2016-04-14 02:15:43

IanParcs (66 views)
2016-04-12 03:51:16

IanParcs (35 views)
2016-04-12 03:50:03

IanParcs (32 views)
2016-04-12 03:49:54

IanParcs (27 views)
2016-04-12 03:49:52

IanParcs (36 views)
2016-04-12 03:49:52
Website offering 3D Models specifically for games for free
by vusman
2016-04-29 12:56:17

List of Learning Resources
by SilverTiger
2016-02-05 09:39:47

List of Learning Resources
by SilverTiger
2016-02-05 09:38:38

List of Learning Resources
by SilverTiger
2016-02-05 09:35:50

Rendering resources
by Roquen
2015-11-13 14:37:59

Rendering resources
by Roquen
2015-11-13 14:36:58

Math: Resources
by Roquen
2015-10-22 07:46:10

Networking Resources
by Roquen
2015-10-16 07:12:30 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!