Racing engine script?

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
User avatar
0bsidian
Posts: 1118
Joined: Sun Oct 28, 2012 11:59 pm
Location: New Zealand

Re: Racing engine script?

Post by 0bsidian »

Ditto. Any links to the threads?
User avatar
The Zombie Killer
Posts: 1528
Joined: Thu Jul 14, 2011 12:06 am
Location: Gold Coast, Queensland, Australia

Re: Racing engine script?

Post by The Zombie Killer »

How's this so far?
It's only basic car handling at the moment, I'm going to get around to proper (or at least better) car physics later.
It's probably extremely laggy in GL because I'm using a voxel model for the car, I've been testing it in software.

And please ignore the fact that the model is a car and not a kart :p I've been playing too much Carmageddon lately
doomkart.pk3
(20.73 KiB) Downloaded 61 times
User avatar
Nash
 
 
Posts: 17506
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: Racing engine script?

Post by Nash »

Looking at the contents of that PK3 I can sort of deduce that he seems like some kind of douchebag. Hahaha WTF bro, "encrypting" DECORATE/ACS code seriously?

TZK: It's a nice start! But by god that 35 FPS jerkiness is REALLY starting to get on my nerves. >:( Don't worry this isn't your fault BTW. I'm just so bloody upset that there are so many awesome non-conventional things that can be done with ACS and people are coming up with wackier and crazier things all the time. But they look like shit because SetActorPosition isn't interpolated... =/ Sorry for the rant heh. You should expand on it further. Add skidding, decrease the deceleration rate (it's too fast ATM), etc.
User avatar
The Zombie Killer
Posts: 1528
Joined: Thu Jul 14, 2011 12:06 am
Location: Gold Coast, Queensland, Australia

Re: Racing engine script?

Post by The Zombie Killer »

Nash wrote:TZK: It's a nice start! But by god that 35 FPS jerkiness is REALLY starting to get on my nerves. >:( Don't worry this isn't your fault BTW. I'm just so bloody upset that there are so many awesome non-conventional things that can be done with ACS and people are coming up with wackier and crazier things all the time. But they look like shit because SetActorPosition isn't interpolated... =/ Sorry for the rant heh. You should expand on it further. Add skidding, decrease the deceleration rate (it's too fast ATM), etc.
Yeah, the 35 fps thing is really annoying. It's one of the main reasons I wanted to change the ticrate a while ago.
As for skidding, I tried to add that, but it didn't work too well, I haven't given up on trying though of course.
And yeah, the deceleration is a bit too quick, for some reason the code bugs out if I try to use decimals though, using FixedMul/FixedDiv didn't do a hell of a lot either. I think I'm doing something wrong in that respect.

Thanks for the feedback
User avatar
GooberMan
Posts: 1336
Joined: Fri Aug 08, 2003 12:57 am
Location: Helsinki, Finland

Re: Racing engine script?

Post by GooberMan »

The secret is to not use SetActorPosition instead of changing the tic rate.

I haven't looked at it yet, but I'll load it up and modify it a bit when I'm at my computer.
User avatar
The Zombie Killer
Posts: 1528
Joined: Thu Jul 14, 2011 12:06 am
Location: Gold Coast, Queensland, Australia

Re: Racing engine script?

Post by The Zombie Killer »

@GooberMan
I'm interested in what other solutions you have, any improvements are very welcome.
User avatar
Nash
 
 
Posts: 17506
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: Racing engine script?

Post by Nash »

[offtopic] wow that was a pretty shitty rant. Sorry about that. I posted it right after a long and tiring day (7 hours of soundcheck in preparation for a little gig tomorrow) and I just went full on asdafdsfgfsdg. Sorry. ;( I don't mean it in such an agressive and ungrateful way.
User avatar
GooberMan
Posts: 1336
Joined: Fri Aug 08, 2003 12:57 am
Location: Helsinki, Finland

Re: Racing engine script?

Post by GooberMan »

Alright, so this is my first version of kart physics. I started scripting from scratch because I didn't like how the previous scripts were written. No offense meant.

Rather than keeping track of a bunch of variables in map arrays, I'm relying on the fact that the kart physics script will execute for each player in the map and have structured my scripts and functions to be self-contained as a result.

I'm using the already existing velocity value and augmenting it with simple Euler Integration. There's several places i need to go from here to make it feel right - proper friction, torque to some degree, altering the turning circle based on velocity, and a few other things. You'll notice, though, that even in first person Doom Guy moves quite differently to how he used to.

In the case of friction, is there no reliable way of turning friction off in ZDoom? I'd want to define friction values per surface. Braking will be handled by the friction algorithm.

I'm handling gravity myself. Turning off jump. But jumping still does something. Hmmm. Need to look in to that further.

The third person camera is "smoother" than it used to be. A lot of the jerkiness comes from manipulating a third person camera. I've put some groundwork in to a third person camera that exploits the smooth movement of interpolation points and moving cameras. It's not there yet, you'll notice some very ugly rubber banding if you turn it on in the options menu, but the stop motion jerkiness is gone at the very least.

One bad thing about this camera method - I'd rather just spawn the cameras myself and set the specials so that they don't interfere with map placement. Can't do that. If I spawn a moving camera, it immediately has a whinge about parameters not set. Setting them after doesn't work, and the ACS script unloads at some point.

I probably won't get another chance to look at this for a couple of weeks. But it's a solid start.
Attachments
gooberkart_0.001.pk3
Initial pass of kart physics and third person camera
(23.42 KiB) Downloaded 42 times
User avatar
The Zombie Killer
Posts: 1528
Joined: Thu Jul 14, 2011 12:06 am
Location: Gold Coast, Queensland, Australia

Re: Racing engine script?

Post by The Zombie Killer »

GooberMan wrote:I started scripting from scratch because I didn't like how the previous scripts were written. No offense meant.
None taken. I did the scripts very quickly and the special camera I made was just a copy-paste from something I did earlier.
tl;dr, the scripts were far from final. (not only that but they were quite ugly too, I'm not proud of them in their current state)
GooberMan wrote:Rather than keeping track of a bunch of variables in map arrays,
Yeah, I didn't really intend to do that, but it worked when I did it quickly so I left it in as a temporary method while I finish off the more important stuff.
GooberMan wrote:The third person camera is "smoother" than it used to be
It most certainly is, nice job!
User avatar
GooberMan
Posts: 1336
Joined: Fri Aug 08, 2003 12:57 am
Location: Helsinki, Finland

Re: Racing engine script?

Post by GooberMan »

It was annoying me that my boost functionality wasn't working, and that the camera rubber banded so horribly. So I fixed them both.

Of course, now there's the issue that Doom Guy's visual representation in the world only updates at 35Hz. He moves smoothly, and the camera moves smoothly. I think the rest is beyond my control.

For now.
Attachments
gooberkart0.002.pk3
Now with actual smooth camera1
(24.77 KiB) Downloaded 38 times
User avatar
Marrub
 
 
Posts: 1207
Joined: Tue Feb 26, 2013 2:48 pm
Preferred Pronouns: No Preference
Operating System Version (Optional): Arch Linux
Graphics Processor: ATI/AMD with Vulkan/Metal Support
Contact:

Re: Racing engine script?

Post by Marrub »

wildweasel wrote:
Marrub wrote:please don't bring this up again anywhere, we've had to explain this numerous times and all of it was just a waste of time thank you
This is actually the first I've heard of this.
yeah, but it's about the twentieth time I've heard it.
I was there when all of this happened.. never again.
User avatar
GooberMan
Posts: 1336
Joined: Fri Aug 08, 2003 12:57 am
Location: Helsinki, Finland

Re: Racing engine script?

Post by GooberMan »

So this is what happens when something bugs me. It gets stuck in my head and I keep at it after I put it down (and accidentally delete Prime Directive again...)

This version has gone from "Okay, cool story bro" to "Wow, that's showing real potential". I pushed through my camera problems to work out where the glitchy behaviour was coming from. Turns out that if you Thing_Activate() a moving camera, it doesn't restart its path if it's already following one. The rubber banding, subsequently, can be completely disabled by doing a Thing_Deactivate() first.

In English, I believe this is the first working example of a smooth third person camera in ZDoom.

I also did a bit of work to put the car back in. I spawn a dummy actor and set its velocity to the player's. As it's a collision-less actor, I occasionally need to reset its position to the player (ie whenever it collides with something). SetActorPosition just does horribly horrible things to actors, so while I'd have really preferred to SetActorPosition() and SetActorVelocity() at all times on the dummy actor the simple reality is that it doesn't work thanks to some nasty behind-the-scenes junk.

Still, the net result is that you get a bonnet cam in first person mode, and a smooth third-person cam.

I might turn this in to a full mod once I'm done with Prime Directive, actually.
Attachments
gooberkart0.003.pk3
Now with added awesome.
(30.54 KiB) Downloaded 59 times
User avatar
The Zombie Killer
Posts: 1528
Joined: Thu Jul 14, 2011 12:06 am
Location: Gold Coast, Queensland, Australia

Re: Racing engine script?

Post by The Zombie Killer »

Indeed that really has potential, awesome work GooberMan!
And that third person camera really is awesome, mind if I mess around with it for a bit?
User avatar
Enjay
 
 
Posts: 27307
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: Racing engine script?

Post by Enjay »

That is indeed pretty cool.

So, now we need a reverse gear with suitable steering adjustments and the car shouldn't be able to turn when there is no forward/rearward motion. ;)
User avatar
The Zombie Killer
Posts: 1528
Joined: Thu Jul 14, 2011 12:06 am
Location: Gold Coast, Queensland, Australia

Re: Racing engine script?

Post by The Zombie Killer »

@GooberMan
Success!
After a bit of messing around, I managed to spawn a moving camera and its interpolation points in acs:

EDIT: Redundant parts removed.

Code: Select all

Script "MovingCameraTest" ENTER
{
    // Define variables
    int tid, point1, point2;
    
    // Spawn Point 1
    point1 = UniqueTID(-32767, 32767);
    Spawn("InterpolationPoint", 0.0, 0.0, 0.0, point1);
    
    // Spawn Point 2
    point2 = UniqueTID(-32767, 32767);
    Spawn("InterpolationPoint", 0.0, 0.0, 0.0, point2);
    
    // Set Point 1's Args
    SetThingSpecial(point1, 0, 0, 1, 0, point2, 0);
    
    // Set Point 2's Args
    SetThingSpecial(point2, 0, 0, 0, 1, 0, 0);
    
    // Spawn the MovingCamera
    tid = UniqueTID(-32767, 32767);
    Spawn("MovingCamera", 0.0, 0.0, 0.0, tid);
    
    // Set its args
    SetThingSpecial(tid, 0, point1, 0, 7, 0, 0);
} 
Here's your camera code with it implemented:

Code: Select all

// ACS
#library "camera"
#include "zcommon.acs"

// Smooth third person camera
// Base code by GooberMan with minor
// modifications by The Zombie Killer.

// Defines
#define cvarThirdPerson "cl_thirdperson"
#define cvarCamDist "cl_camdist"

#define ONETIC 0.02857
#define VIEW_HEIGHT 56.0
#define VIEW_PITCH 0.03125

// Scripts
Script "Camera" (void)
{
	// Let's define our variables
	int camTID, interpPoint1TID, interpPoint2TID;
	
	// And spawn our interpolation points
	interpPoint1TID = UniqueTID(-32767, 32767);
	Spawn("InterpolationPoint", 0.0, 0.0, 0.0, interpPoint1TID);
	interpPoint2TID = UniqueTID(-32767, 32767);
	Spawn("InterpolationPoint", 0.0, 0.0, 0.0, interpPoint2TID);
	
	// Now set their arguments
	SetThingSpecial(interpPoint1TID, 0, 0, 1, 0, interpPoint2TID, 0);
	SetThingSpecial(interpPoint2TID, 0, 0, 0, 1, 0, 0);
	
	// Now we spawn the camera
	camTID = UniqueTID(-32767, 32767);
	Spawn("MovingCamera", 0.0, 0.0, 0.0, camTID);
	
	// And set its args
	SetThingSpecial(camTID, 0, interpPoint1TID, 0, 7, 0, 0);
	
	// Now for GooberMan's camera code
	int targetActor = ActivatorTID();
	
	// To get smooth camera movement, we're using a moving camera with
	// interpolation points
	int lastCamX = GetActorX(targetActor);
	int lastCamY = GetActorY(targetActor);
	int lastCamZ = GetActorZ(targetActor) + VIEW_HEIGHT;
	int lastCamAngle = GetActorAngle(targetActor);
	
	While (true)
	{
		int maxDistance = ToFixed(GetCVar(cvarCamDist));
		
		int targetX = GetActorX(targetActor);
		int targetY = GetActorY(targetActor);
		int targetZ = GetActorZ(targetActor) + VIEW_HEIGHT;
		int targetAngle = GetActorAngle(targetActor);
		
		int targetCosAngle = Cos(targetAngle);
		int targetSinAngle = Sin(targetAngle);
		
		int camAddX = FixedMul(-maxDistance, targetCosAngle);
		int camAddY = FixedMul(-maxDistance, targetSinAngle);
		
		// This is the easy bit - the first interpolation point needs to be the
		// camera's current position
		
		SetActorPosition(interpPoint1TID, lastCamX, lastCamY, lastCamZ, false);
		SetActorAngle(interpPoint1TID, lastCamAngle);
		SetActorPitch(interpPoint1TID, VIEW_PITCH);
		
		// This is where it all gets a bit tricky. As we're using camera interpolation
		// for smooth camera movement, we need to set the target interpolation node
		// 8 time further away from the source node than it needs to be.
		int newCamX = targetX + camAddX;
		int newCamY = targetY + camAddY;
		
		int angleAdd = AngleDiff(lastCamAngle, targetAngle);
		
		int camDiffX = FixedMul(newCamX - lastCamX, 8.0);
		int camDiffY = FixedMul(newCamY - lastCamY, 8.0);
		
		int camX = lastCamX;
		int camY = lastCamY;
		int camAngle = lastCamAngle;
		
		lastCamX = newCamX;
		lastCamY = newCamY;
		lastCamZ = targetZ;
		lastCamAngle = targetAngle;
		
		newCamX = camX + camDiffX;
		newCamY = camY + camDiffY;
		
		SetActorPosition(interpPoint2TID, newCamX, newCamY, targetZ, false);
		SetActorAngle(interpPoint2TID, (lastCamAngle + FixedMul(angleAdd, 8.0)) & 0x0000FFFF);
		SetActorPitch(interpPoint2TID, VIEW_PITCH);
		
		// Done! Now activate the camera and watch the smooth.
		Thing_Deactivate(camTID);
		Thing_Activate(camTID);
		
		if (GetCVar(cvarThirdPerson))
			ChangeCamera(camTID, false, false);
		else
			ChangeCamera(0, false, false);
		Delay(1);
	}
}

// Functions
Function int ToFixed (int value)
{
	return value << 16;
}

Function int AngleDiff (int sourceAngle, int targetAngle)
{
	int diff = targetAngle - sourceAngle;
	
	if (diff >= 0.5)
		diff -= 1.0;
	else if (diff < -0.5)
		diff += 1.0;
	
	return diff;
}
Locked

Return to “Editing (Archive)”