Gamestudio Links
Zorro Links
Newest Posts
Issue with Starter Window
by txesmi. 10/23/19 09:22
Accessing All Historical Price Data
by JohnJits. 10/22/19 22:37
file_write var array ?
by laz. 10/22/19 16:00
SAV_STATS
by MatPed. 10/22/19 13:57
Instrument Price Zorro Chart
by jcl. 10/22/19 10:39
Calculating with price series
by AndrewAMD. 10/21/19 14:31
Error E355: Startup failure
by Dooley. 10/21/19 06:47
AUM Magazine
Latest Screens
The Space Between
Pogostuck: Rage With Your Friends
Worst Case Z
AckCon'18 - Lotter vs the World 2 - Preview Release
Who's Online Now
10 registered members (AndrewAMD, Uhrwerk, jenGs, MatPed, kvm, 20BN, Paulius, Dalla, 2 invisible), 635 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Bolle, VillageTalkies, line7, Shutch, Clifford_B
18311 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Flying entities #475296
12/01/18 07:29
12/01/18 07:29
Joined: Jan 2018
Posts: 4
Kigali, Rwanda
Pacific Offline OP
Guest
Pacific  Offline OP
Guest

Joined: Jan 2018
Posts: 4
Kigali, Rwanda
Can someone help me with the code to control helicopter with physics engine?
please...

Last edited by Pacific; 12/01/18 07:30.

pac++
Re: Flying entities [Re: Pacific] #475317
12/01/18 18:53
12/01/18 18:53
Joined: Jun 2007
Posts: 1,264
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,264
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!

Re: Flying entities [Re: txesmi] #475509
12/17/18 17:57
12/17/18 17:57
Joined: Jan 2018
Posts: 4
Kigali, Rwanda
Pacific Offline OP
Guest
Pacific  Offline OP
Guest

Joined: Jan 2018
Posts: 4
Kigali, Rwanda
Thanks a lot for this!


pac++

Moderated by  HeelX, Spirit 

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