Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, alibaba), 1,426 guests, and 9 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19055 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Camera #320868
04/25/10 14:27
04/25/10 14:27
Joined: Apr 2009
Posts: 274
atari98 Offline OP
Member
atari98  Offline OP
Member

Joined: Apr 2009
Posts: 274
Code:
//Settings:
STRING* wheel_model_name = "buggy_rad1.mdl";

var car_maxAngSpeed = 70;
var car_maxTorqueBrake = 1000;
var car_maxTorque = 1000;
var car_suspensionERP = 95000;
var car_suspensionCFM = 50;
VECTOR* car_fl_offset = {x=23.5; y=16.5; z=-6;}
VECTOR* car_fr_offset = {x=23.5; y=-16.5; z=-6;}
VECTOR* car_rl_offset = {x=-35.5; y=15.5; z=-6;}
VECTOR* car_rr_offset = {x=-35.5; y=-15.5; z=-6;}

int car_wheel_counter;
VECTOR car_vec_right;
VECTOR* car_vec_up = {z=1;}
ENTITY* car_chassis;
ENTITY* car_wFL;
ENTITY* car_wFR;
ENTITY* car_wRL;
ENTITY* car_wRR;
var car_common_wheel_higth = -100000;
var car_downSpeed;
var car_AngSpeed;
var car_linSpeed;

//Constraints:
var car_fl_const;
var car_fr_const;
var car_rl_const;
var car_rr_const;

function car_SpeedControl();
function car_SteerControl();
function car_Camera();
function car_FLInit();
function car_FRInit();
function car_RLInit();
function car_RRInit();

function car_InitWheel()
{
	set(my, SHADOW);
	if(car_common_wheel_higth <= -100000) car_common_wheel_higth = my.z;
	else my.z = car_common_wheel_higth;
	vec_set(my.skill1, my.x);
	vec_set(my.skill4, my.pan);
	phent_settype(my, PH_RIGID, PH_SPHERE);
	phent_setmass(my, 30, PH_SPHERE);
	phent_setgroup(my, 2);
	phent_setfriction(my, 100);
	phent_setdamping(my, 15, 10);
	phent_setelasticity(my, 0, 100);
	car_wheel_counter++;
}

function car_ChassisInit()
{
	vec_set(my.skill1, my.x);
	vec_set(my.skill4, my.pan);
	set(my, SHADOW | PASSABLE);
	vec_set(car_vec_right, vector(0, -1, 0));
	vec_rotate(car_vec_right, my.pan);
	phent_settype(my, PH_RIGID, PH_BOX);
	phent_setmass(my, 10, PH_BOX);
	phent_setgroup(my, 2);
	phent_setfriction(my, 20);
	phent_setdamping(my, 5, 5);
	phent_setelasticity(my, 10, 100);
	car_chassis = my;
	VECTOR* wheel_pos;
	vec_set(wheel_pos, car_fl_offset);
	vec_rotate(wheel_pos, car_chassis.pan);
	vec_add(wheel_pos, car_chassis.x);
	ent_create(wheel_model_name, wheel_pos, car_FLInit);
	vec_set(wheel_pos, car_fr_offset);
	vec_rotate(wheel_pos, car_chassis.pan);
	vec_add(wheel_pos, car_chassis.x);
	ent_create(wheel_model_name, wheel_pos, car_FRInit);
	vec_set(wheel_pos, car_rl_offset);
	vec_rotate(wheel_pos, car_chassis.pan);
	vec_add(wheel_pos, car_chassis.x);
	ent_create(wheel_model_name, wheel_pos, car_RLInit);
	vec_set(wheel_pos, car_rr_offset);
	vec_rotate(wheel_pos, car_chassis.pan);
	vec_add(wheel_pos, car_chassis.x);
	ent_create(wheel_model_name, wheel_pos, car_RRInit);
	while(car_wheel_counter < 4) wait(1);
	reset(my, PASSABLE);
	ph_setgravity(vector(0, 0, -1800));
}

function car_FLInit()
{
	my.pan = you.pan;
	set(my, PASSABLE);
	while(!car_chassis) wait(1);
	car_wFL = my;
	car_InitWheel();
	car_fl_const = phcon_add(PH_WHEEL, car_chassis, my);
	phcon_setparams1(car_fl_const, my.x, car_vec_up, car_vec_right);
	phcon_setparams2(car_fl_const, nullvector, nullvector, vector(car_suspensionERP, car_suspensionCFM, 0));
	reset(my, PASSABLE);
}

function car_FRInit()
{
	my.pan = you.pan;
	my.pan += 180;
	set(my, PASSABLE);
	while(!car_chassis) wait(1);
	car_wFR = my;
	car_InitWheel();
	car_fr_const = phcon_add(PH_WHEEL, car_chassis, my);
	phcon_setparams1(car_fr_const, my.x, car_vec_up, car_vec_right);
	phcon_setparams2(car_fr_const, nullvector, nullvector, vector(car_suspensionERP, car_suspensionCFM, 0));
	reset(my, PASSABLE);
}

function car_RLInit()
{
	my.pan = you.pan;
	set(my, PASSABLE);
	while(!car_chassis) wait(1);
	car_wRL = my;
	car_InitWheel();
	car_rl_const = phcon_add(PH_WHEEL, car_chassis, my);
	phcon_setparams1(car_rl_const, my.x, car_vec_up, car_vec_right);
	phcon_setparams2(car_rl_const, nullvector, nullvector, vector(car_suspensionERP, car_suspensionCFM, 0));
	reset(my, PASSABLE);
}

function car_RRInit()
{
	my.pan = you.pan;
	my.pan += 180;
	set(my, PASSABLE);
	while(!car_chassis) wait(1);
	car_wRR = my;
	car_InitWheel();
	car_rr_const = phcon_add(PH_WHEEL, car_chassis, my);
	phcon_setparams1(car_rr_const, my.x, car_vec_up, car_vec_right);
	phcon_setparams2(car_rr_const, nullvector, nullvector, vector(car_suspensionERP, car_suspensionCFM, 0));
	reset(my, PASSABLE);
}

action car_chassis_action()
{
	car_wheel_counter = 0;
	player = my;
	car_ChassisInit();
	while(car_wheel_counter < 4) wait(1);
	car_SpeedControl();
	car_SteerControl();
	car_Camera();
}

function car_SpeedControl()
{
	var direction;
	var usejoy = 0;
	var rotSign;
	if(car_wRL.pan != car_wRR.pan) rotSign = -1;
	else rotSign = 1;
	var angSpeedRL;
	var angSpeedRR;

	var targetSpeed;
	while(1)
	{
		//Update Speed:
		phent_getvelocity(car_chassis, target, nullvector);
		car_downSpeed = target.z * 0.091;
		target.z = 0;
		car_linSpeed = vec_length(target) * 0.091;

		phent_getangvelocity(car_wRL, target);
		angSpeedRL = target.y;
		phent_getangvelocity(car_wRR, target);
		angSpeedRR = target.y;
		if(abs(angSpeedRL) > abs(angSpeedRR))
		{
			car_AngSpeed = angSpeedRL;
		}
		else
		{
			car_AngSpeed = rotSign * angSpeedRR;
		}
		//--------------
		//Speed Control:
		direction = key_cuu - key_cud;
		if((car_AngSpeed > 5 && direction < 0) || (car_AngSpeed < -5 && direction > 0))
		{
			targetSpeed = 0;
			if(abs(car_AngSpeed) > 0.25 * car_maxAngSpeed)
			{
				phcon_setmotor(car_rl_const, nullvector, vector(car_AngSpeed * 0.5, 0.5 * car_maxTorqueBrake, 0), nullvector);
				phcon_setmotor(car_rr_const, nullvector, vector(car_AngSpeed * 0.5, 0.5 * car_maxTorqueBrake, 0), nullvector);
			}
			else
			{
				phcon_setmotor(car_rl_const, nullvector, vector(0, car_maxTorqueBrake, 0), nullvector);
				phcon_setmotor(car_rr_const, nullvector, vector(0, car_maxTorqueBrake, 0), nullvector);
			}
		}
		else
		{
			var oldSpeed;
			oldSpeed = targetSpeed;
			targetSpeed += direction * time_step * 2;
			var torque;
			torque = car_maxTorque;
			if(!usejoy && direction == 0)
			{
				targetSpeed *= 1 - (time_step * 0.02);
				torque = car_maxTorque / 2;
				if(abs(car_linSpeed) < 20)
				{
					torque = 0;
					targetSpeed *= 0.5;
				}
			}
			else
			{
				if(usejoy && abs(targetSpeed) < abs(car_AngSpeed))
				{
					torque = car_maxTorque / 2;
				}
			}
			targetSpeed = clamp(targetSpeed, -car_maxAngSpeed * 0.25, car_maxAngSpeed);
			phcon_setmotor(car_rl_const, nullvector, vector(targetSpeed, torque, 0), nullvector);
			phcon_setmotor(car_rr_const, nullvector, vector(targetSpeed, torque, 0), nullvector);
		}
		wait(1);
	}
}

function car_SteerControl()
{
	var direction = 0;
	var usejoy;
	var targetSteer;
	while(1)
	{
		direction = key_cur - key_cul;
		direction *= (1-(abs(car_AngSpeed) / (car_maxAngSpeed + 60)));
		targetSteer = 30 * direction;
		targetSteer = clamp(targetSteer, -30, 30);
		if(direction != 0)
		{
			phcon_setparams2(car_fl_const, vector(targetSteer, targetSteer, 0), nullvector, vector(car_suspensionERP, car_suspensionCFM, 0));
			phcon_setparams2(car_fr_const, vector(targetSteer, targetSteer, 0), nullvector, vector(car_suspensionERP, car_suspensionCFM, 0));
		}
		else
		{
			targetSteer *= 1 - (time_step * 0.25);
			if(abs(targetSteer) < 1) targetSteer = 0;
			phcon_setparams2(car_fl_const, vector(targetSteer, targetSteer, 0), nullvector, vector(car_suspensionERP, car_suspensionCFM, 0));
			phcon_setparams2(car_fr_const, vector(targetSteer, targetSteer, 0), nullvector, vector(car_suspensionERP, car_suspensionCFM, 0));
		}
		wait(1);
	}
}

//camera settings:


//----------------


function car_Camera()
{

	while(1)
	{
		
		{
	   vec_set(camera.x,vector(-200,0,60));
		vec_rotate(camera.x,camera.pan);
      vec_add(camera.x,my.x);
			
		}
		
		wait(1);
	}
}






Warum funzt die kamera nicht: Wie mache ich, das die kamerahinter dem fahrezeug hinterher fährt?

Code:
function car_Camera()
{

	while(1)
	{
		
		{
	   vec_set(camera.x,vector(-200,0,60));
		vec_rotate(camera.x,camera.pan);
      vec_add(camera.x,my.x);
			
		}
		
		wait(1);
	}





Gruss
Atari98 wink


Meine Fun Websiten
www.free4-fun.de.tl

www.gamer-liga-live.de.tl

Meine Game-Projekt Websiten
www.gamer-projects.de.tl
Re: Camera [Re: atari98] #320872
04/25/10 14:57
04/25/10 14:57
Joined: Aug 2007
Posts: 1,922
Schweiz
Widi Offline
Serious User
Widi  Offline
Serious User

Joined: Aug 2007
Posts: 1,922
Schweiz
here you go:
--------------------------------------------------------
camera.x = my.x - 200 * cos(my.pan);
camera.y = my.y - 200 * sin(my.pan);
camera.z = my.z + 200;
camera.pan = my.pan;
camera.tilt = -30;
----------------------------------------------------------


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1