[CODE] Better c_move (with game template in the works)

Posted By: MatAllum

[CODE] Better c_move (with game template in the works) - 03/02/12 21:34

Edit to this post: The template provided on this first post only provides a c_move workaround script and not the "better c_move" mentioned in the title of this thread. See my post below (containing the player_move() function) for the code snippet you probably came here for.

*****************

I've seen a number of rants on this forum about the OBB collision system that's been forced on us since A6.40, and having had insane amounts of trouble with collision under any settings myself, I've come up with a solution for simple games.

I created a simple c_trace-based collision detection system for first-person games. Simple is the key word here - it allows climbing of steps and slopes, but Z movement is otherwise restricted (there's no gravity and no jumping). The system is also a little glitchy at the moment (but certainly better than what I've done with the new c_move), but I'm sure someone could check that out if there's enough interest in this project.

I wrapped up the collision system inside a well-documented template for adventure/stealth/horror games (inspired by Amnesia: The Dark Descent). It includes the following features:

-Movement. Obviously. Player and camera movement are smoothed and feel professional as far as I can see.
-Crouching (with un-crouch collision detection/avoidance)
-Leaning around corners
-Displaying short messages on the screen
-Interaction with level objects - tiny center dot turns to a hand in one of two positions depending on how you interact with an object
-Player's visibility is tracked, and can be passed to monster scripts so that the player can hide in the shadows.

It can be downloaded here:
http://www.mediafire.com/file/v42eclp7mz21mu7/XYhalfZCollision.rar

Does anyone find this helpful? Should I add or fix anything before I drop this into the user contributions board?
Posted By: 3run

Re: Simple template for A6 users who hate the collision system - 03/02/12 23:38

Works very smooth, tested it with A8 COM!! laugh Why don't you add jumping, that way it will be more useful!
Will you make lite-c version? If no, I could try to convert it into lite-c, I think it'll be easy.
Posted By: MatAllum

Re: Simple template for A6 users who hate the collision system - 03/03/12 00:11

I will indeed attempt to add proper Z support if you think that would be useful. (I agree it would be, just not sure my scripting is quite good enough yet - my previous attempt was a bit glitchy)

I have no experience with lite-C, but you're welcome to do that - maybe wait until it's all ironed out first?

Anyway, glad you had success with running it!
Posted By: 3run

Re: Simple template for A6 users who hate the collision system - 03/03/12 00:35

Yeah, I better wait till it'll be ironed out first laugh Waiting for update!
Posted By: 3run

Re: Simple template for A6 users who hate the collision system - 03/03/12 19:25

Leaning around corners should be improved mate, players leans throw the objects without any problems laugh Sorry for double post, keep this up!!
Posted By: MatAllum

Re: Simple template for A6 users who hate the collision system - 03/04/12 01:40

Whoops! I thought the default lean distance (11) averted that issue, but I guess it's still too much.

Anyway, still working (on and off) on decent Z movement, so we'll see where this goes.

Edit: You know, when I released this I felt pretty good about my programming. Now seeing how difficult it is to implement Z movement into this particular script makes me doubt that a little bit. I'll keep working at it, but currently it's.... nauseating at best.
Posted By: MatAllum

Re: Simple template for A6 users who hate the collision system - 03/06/12 18:44

Okay, so the setup provided here works for simple adventure titles, I guess, but it's inadequate for plenty of projects, and the collision is buggy and it's really not a replacement for a c_move (just a workaround).

So I did a little searching around this forum and found an algorithm for calculating GLIDE from a simple trace. If anyone still wants a complete "horror template," I can still do that - but until then, enjoy this quick single-trace move.

NOTE: It still needs work! Touching two solid surfaces at once allows you to phase through walls in this script - I still need to add another trace or two to make it perfect.

Code:
var move_vel;
var move_dot;
var move_vec[3];
var move_vec2[3];

function player_move(&velocity)
{
	vec_set(move_vec, velocity);
	move_vel = vec_length(velocity);
	if(move_vel == 0)
	{
		vec_set(my_speed, nullvector);
		return;
	}
	vec_set(temp, my.x);
	vec_add(temp, move_vec);
	
	result = c_trace(my.x, temp, ignore_passable+ignore_passents+ignore_me+use_box+ignore_push);
	if(!trace_hit)
	{
		vec_set(my_speed, temp);
		vec_sub(my_speed, my.x);
		vec_set(my.x, temp);
	}
	else
	{
		move_dot = vec_dot(move_vec, normal)/move_vel;
		vec_set(temp, normal);
		vec_scale(temp, abs(move_dot)*move_vel);
		vec_set(move_vec2, move_vec);
		vec_add(move_vec2, temp);
		
		vec_add(my.x, move_vec2);
		vec_set(my_speed, move_vec2);
	}
}



I swapped out c_move for this function in my other hobby project (rewrite of my Halo clone) and it worked almost flawlessly.
© 2024 lite-C Forums