Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (480)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (547)
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 3677 times)
0 Members and 1 Guest are viewing this topic.
Offline ddfh

Junior Member


Medals: 1



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

Hi,

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:
1  
2  
3  
4  
5  
6  
7  
...
<path
   style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
   d="m 196.47467,414.45085 ... etc."
   id="path2985"
   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:
http://badlogicgames.com/forum/viewtopic.php?f=11&t=7510&sid=de880d0aeef7c7237ea3e1e496cd2842

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.
http://www.greensock.com/v12/
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.

Thanks...
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 128
Projects: 4
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 Ninja


Medals: 43



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

Try tris code https://github.com/fr1zle/OpenMali/blob/master/openmali/src/main/java/org/openmali/curves/CubicBezierSpline.java

- 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 »

 Shocked

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

Offline cylab

JGO Ninja


Medals: 43



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

well... thanks  Tongue

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

Junior Member


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 Member


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): http://rocketmandevelopment.com/2010/06/11/steering-behaviors-seeking/

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

JGO Ninja


Medals: 43



« 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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

atombrot (25 views)
2014-08-19 09:29:53

Tekkerue (24 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (13 views)
2014-08-16 06:20:21

Tekkerue (20 views)
2014-08-16 06:12:11

Rayexar (58 views)
2014-08-11 02:49:23

BurntPizza (38 views)
2014-08-09 21:09:32

BurntPizza (30 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38

BurntPizza (67 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org 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‑gaming.org
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!