Gamestudio Links
Zorro Links
Newest Posts
New Zorro v1.99.2
by jcl
46 minutes 0 seconds ago
Strategy Development
by AndrewAMD
59 minutes 37 seconds ago
closing profitable trades (stop)
by MINER
Today at 12:47
Next contest?
by jcl
Yesterday at 15:44
advance decline (ADO) code examples?
by 3dgamelight
12/09/18 19:52
Newbie coding question. HELP Please!
by 3dgamelight
12/09/18 16:28
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14
12/08/18 19:10
AUM Magazine
Latest Screens
Worst Case Z
AckCon'18 - Lotter vs the World 2 - Preview Release
Evonet Beta v1.0 : Online Project Development Template
Lake scene
Who's Online
19 registered (alibaba, ags, Artvin, AndrewAMD, chsmac85, 20BN, CocaCola, Ayumi, 5 invisible), 477 Guests and 12 Spiders online.
Key: Admin, Global Mod, Mod
Newest Members
mahomed, bondz, Neil_G, bobby4h, MutilatedDuck
18117 Registered Users
Topic Options
Rate This Topic
#475296 - 12/01/18 08:29 Flying entities
Pacific Offline
Guest

Registered: 01/13/18
Posts: 2
Can someone help me with the code to control helicopter with physics engine?
please...


Edited by Pacific (12/01/18 08:30)

Top
#475317 - 12/01/18 19:53 Re: Flying entities [Re: Pacific]
txesmi Online
Serious User

Registered: 06/13/07
Posts: 1192
Loc: Hiporope and its pain
Hi,
you can set the movement speed of a physX actor by 'pXent_setvelocity'. If you set the speed each frame you are actually making it work like 'c_move' in global coordinates but inside the physX engine. 'pXent_setangvelocity' lets you control the actors rotation speed.

Set a vector as movement speed and accelerate it by key input.
W/S:front/back
A/D:left/right
cursorUp/cursorDown:up/down
Code:
my.skMoveX = clamp(my.skMoveX + (key_w - key_s) * ACCELERATION, -MAX_SPEED, MAX_SPEED) * RESISTANCE;
my.skMoveY = clamp(my.skMoveY + (key_a - key_d) * ACCELERATION, -MAX_SPEED, MAX_SPEED) * RESISTANCE;
my.skMoveZ = clamp(my.skMoveZ + (key_cuu - key_cud) * ACCELERATION, -MAX_SPEED, MAX_SPEED) * RESISTANCE;



Then compute tilt and roll speed in reference to the movement and pan with an accelerated skill.
cursorLeft/cursorRight:rotateCCW/rotateCW
Code:
my.skRotX = my.skMoveY * ROLL_FACTOR - ang(my.roll) * RESTORE_FACTOR;
my.skRotY = my.skMoveX * TILT_FACTOR + ang(my.tilt) * RESTORE_FACTOR;
my.skRotZ = clamp(my.skRotZ + (key_cul - key_cur) * ACCELERATION, -MAX_ROT_SPEED, MAX_ROT_SPEED) * RESISTANCE;



Disclaimer: I never deeply tested this workaround, but it seams to work

Click to reveal..

Code:
#include <acknex.h>
#include <ackphysx.h>

#define PRAGMA_PATH "%EXE_DIR%templatesimages"
#define PRAGMA_PATH "%EXE_DIR%templatesmodels"

#define GRAVITY      100

BMAP *bmpTerrain = "rock.tga";

#define skMoveX         skill1
#define skMoveY         skill2
#define skMoveZ         skill3
#define skRotatX        skill4
#define skRotatY        skill5
#define skRotatZ        skill6

action actHc() {
	my->pan = 25;
	my->flags |= SHADOW;
	vec_fill(my->skMoveX, 0);
	vec_fill(my->skRotatX, 0);
	pXent_settype(me, PH_RIGID, PH_BOX);
	
	while(!key_esc) {
		var _accel = 100 * time_step;
		var _factor = 1 - time_step * 0.2;
		my->skMoveX = clamp(my->skMoveX + (key_w - key_s) * _accel, -400, 800) * _factor;
		my->skMoveY = clamp(my->skMoveY + (key_a - key_d) * _accel, -500, 500) * _factor;
		my->skMoveZ = clamp(my->skMoveZ + (key_cuu - key_cud) * _accel, -200, 200) * _factor;
		VECTOR _vMove;
		vec_set(&_vMove, &my->skMoveX);
		vec_rotate(&_vMove, vector(my->pan, 0, 0));
		pXent_setvelocity(me, &_vMove);
		
		VECTOR _vRot;
		_vRot.x = -ang(my->roll) * 10 - my->skMoveY * 0.6;
		_vRot.y = ang(my->tilt) * 10 + my->skMoveX * 0.2;
		my->skRotatZ = clamp(my->skRotatZ + (key_cul - key_cur) * 4, -80, 80) * _factor;
		_vRot.z = my->skMoveY * 0.01 * my->skMoveX * 0.01 + my->skRotatZ;
		vec_rotate(&_vRot, vector(my->pan, 0, 0));
		pXent_setangvelocity(me, &_vRot);
		
		camera->x = -300;
		camera->y = 0;
		camera->z = 130;
		vec_rotate(&camera->x, vector(my->pan, 0, 0));
		vec_add(&camera->x, &my->x);
		camera->pan = my->pan;
		
		wait(1);
	}
	
	sys_exit(NULL);
}

action actCube() {
	my->pan = random(360);
	vec_fill(my->scale_x, 4);
	my->flags |= SHADOW;
	pXent_settype(me, PH_RIGID, PH_BOX);
}

void main() {
	video_mode = 10;
	fps_max = 60;
	wait(3);
	on_0 = NULL;
	physX_open();
	pX_setunit(0.25);
	pX_setgravity(vector(0, 0, -GRAVITY));
	
	level_load("");
	camera->tilt = -10;
	
	ENTITY *_entTerrain = ent_createterrain(bmpTerrain, nullvector, 1, 1, 16384);
	pXent_settype(NULL, PH_STATIC, PH_PLANE); // create a static plane at groundlevel zero
	
	int _i = 0;
	for(; _i<100; _i+=1)
		ent_create("dumper1.MDL", vector(random(16000)-8000,random(16000)-8000,100), actCube);
	ent_create("buggy.MDL", vector(0,0,400), actHc);
}



Enjoy!

Top



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

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