Moving a car realistically down a street.

Started by Trisk, Fri 18/05/2007 05:31:34

Previous topic - Next topic

Trisk

OK, I've been banging my head against the wall with this, maybe someone else with madder skills can help me. I need to move a car along the middle lane of this street:



Now, because of perspective, it obviously needs to move faster the closer it gets...

I have the animation for the car so it perspective corrects and looks cool, but just moving it as an object, you can't move it any slower than 1 pixel per game cycle, which translates into the car SHOOTING 48 pixels a second down the road. It looks really stupid to say the least...

So, I need to figure out a way to get the car to move realistically, slower in the distance and faster as it closes.

is there a way to make a function that would do this? Ideally, I want to have multiple cars running down this street, all three lanes, so having a function that I could call would be the best way to do it, but it is kinda beyond me at this point...

Any help would be greatly appreciated...

Khris

There are two ways to do it:

1) Use Timers. Instead of moving it 0.5 pixels per game cycle (which is what a speed of 0.5 would do), move it 1 pixel every 2nd cycle. So, set a timer to 2 and if it expires, move the object by one pixel and reset the timer.
However, this will look good only for speeds like 1/2, 1/3, aso.

2) The other way is not to use Object.Move at all but to do it all manually.
Best use a struct to manage the cars and their 3d coords, then translate those into 2d coords and scaling level and display the object accordingly.

A simple way of doing 3D -> 2D:
x2=x3/z3+x_vp;
y2=y_vp-y3/z3;

I'd elaborate on this but I have to go to work now.

GarageGothic

#2
Quote from: KhrisMUC on Fri 18/05/2007 09:44:331) Use Timers. Instead of moving it 0.5 pixels per game cycle (which is what a speed of 0.5 would do), move it 1 pixel every 2nd cycle. So, set a timer to 2 and if it expires, move the object by one pixel and reset the timer. However, this will look good only for speeds like 1/2, 1/3, aso.

Or do indeed move i 0.5 pixels per game cycle :) Store the current speed and the current position as floats (adding the pixels-per-cycle speed to the position every cycle), then assign the x/y coordinates of the object as a FloatToInt every cycle. That way you can also gradually increase the speed as the car gets closer to the camera.

Edit: If you turn the car into a character instead of an object, it might be enough to use the "adjust walking speed to scaling" option.

Gilbert

However, from changes.txt about updates in V2.72:
Quote
- Added ability to use movement speeds slower than 1 (-2 is now 1/2,
   -3 is 1/3, etc)

So that at least the timer method is obsolete now, unless this feature doesn't really work (since it seems that few people had tried it, I didn't try it either).

GarageGothic

#4
That functionality isn't very useful if you need a gradual increase anyway since there's a huge jump between 1 and 1/2.

Edit: In response to Gilbot's reply to this post (very confusing, I know): Sure I think that's the case too. I was just saying that doubling an object's movement speed from one frame to the next isn't exactly smooth. But if you set a fixed speed of 1/2 and adjust walk speed with scaling instead of incrementing the speed, of course that would work fine.

Gilbert

I think it applies also to characters, so you can walk as 1/2, 1/3,... speed AND adjust with scaling at the same time.

SSH

Indeed, I think you can use the negative speeds as has already been said, or you can look at my slowmove module (which does pretty much the same thing) and perhpas adapt it for greater flexibility, if you require it.
12

Trisk

Hey guys, thanks for the replies. I did not know about the negative speeds thing, which may definitely help me to get it working.

The problem with that, is that the speed is still linear, so the car appears to be moving slower the closer it gets on the street.

Adding to this is that the footage (animation frames) of the car I've already shot grow larger 'cause I wasn't thinking about using this as a character and adjusting the speed with scaling. I suppose I could re-shoot it with the car's size staying a constant, but then I am still limited in number of frames that the car animation can contain to one loop, as I want the car to perspective correct as it nears. The problem with THAT is that then I am limited to a very JERKY movement as I must have the car move a large amount of pixels per frame to keep it from looping back to the first frames...unless there is still a way to have a character move independently of its animation cycle, a la Quest for Glory 4 1/2 (hopefully you know what I mean by that,) I just don't see how this can work...

Sorry if I'm not making sense. :( I'm not very good at explaining the problem, but hopefully you begin to see why I'm banging my head.  :-\

Thanks a ton for your help,
Ben

GarageGothic

On one hand I don't want to give up on this issue, as I find it interesting. But practically speaking, as this is for a cutscene, perhaps you would be better off positioning the car and changing the animation frames manually in script. If we're talking less than 50 frames that would be manageable and probably create the best result.

Trisk

:( It's not a cutscene, it's supposed to happen as you play. General traffic is supposed to come along all three lanes of the road randomly as you move about the room...I'm just trying to get one car working for now and then do more after that...

That said I could probably still do it manually, but it would be very annoyingly time consuming.  :P

...I was hopin' one of you programming gods would have a magical formula to apply to situations like this. :)

Ben

Gilbert

Did you really tried the "adjust speed with scaling" option?

Trisk

As previously stated, the sprite itself grows in subsequent frames, so I can only do a very small amount of "adjust speed with scaling." about 35-75% is the outer limit of what I can do. Even at that it starts a bit too small and ends a bit too big.

SSH

It sounds like you're better off using your own code to adjust the x and y of the car each frame rather than using AGS functions, which as you say will mess with animation frames.

Take a look at the code in the slowmove module: http://ssh.me.uk/moddoc/slowmove.zip    and put some stuff in to change the speed according to some reciprocal of the Y position. You may find the Star Wars module, useful too, as it does pespective speed correction: http://ssh.me.uk/moddoc/StarWars.zip
12

SMF spam blocked by CleanTalk