Wave Swinger gondela

Posted By: Polypfreak1987

Wave Swinger gondela - 04/11/09 14:48

Hello,

I am making a fairground ride (Star Flyer (like a very big Wave Swinger)). Now I am at the gondela's. The center piece is rotating around his Z-axis. But now I have to swing the gondela's wich is depends on the speed of the rotation they need to swing at the X-axis. How do I do this?

I have the following code in my gondela action, but it doesn't work.

Code:
action gondel01 {
	gondel1 = my;
	my.passable = on;
	
	phent_settype(my,PH_RIGID,PH_SPHERE);
	phent_setmass(my,1,PH_SPHERE);
	phent_setdamping(my,0,30);
	phent_setfriction(my,10);
	
	phent_setgroup(my,2);
	
	cmolen = phcon_add(PH_HINGE,my,molen_arm);
	phcon_setparams1(cmolen,my.x,vector(1,0,0),nullvector);
	phcon_setparams2(cmolen,vector(-360,360,0),nullvector,nullvector);
	
	while(my) {
		vec_for_vertex(temp,molen_arm,460);
		
		
		my.x = temp.x;
		my.y = temp.y;
		my.z = temp.z;
	
		my.pan = molen_arm.pan+190;
		
		wait(1);
	}
}


Earth gravity is the following code:

Code:
var earthgravity[3] = 0,0, -386;


And this is the main function:

Code:
function main()
{
	//laad het level
	level_load(level_str);
	//video_set(sys_metrics(0),sys_metrics(1),32,1);
	ph_setgravity(earthgravity);
	ph_selectgroup(2);
}


If you don't know waht a Star Flyer is, just look at the following movie:

http://www.youtube.com/watch?v=oDZYJD460ss

It is about the gondela's wich are swinging out when the ride is going to rotate.

Thanks in advanace for your help.
Posted By: XD1v0

Re: Wave Swinger gondela - 04/16/09 13:40

Polypfreak1987 I have code, He does what you want to do, sorry I can not explain how it works because my english is bad.
Source
Code:
 ///////////////////////////////
#include <acknex.h>
#include <default.c>
///////////////////////////////

ENTITY* gondela_ph=NULL;
var gcon;

action gondela ()
{
	phent_settype (my,PH_RIGID,PH_BOX);
	phent_setmass(my,1,PH_SPHERE);
	gcon = phcon_add(PH_HINGE,my,NULL);
	phcon_setparams1(gcon,my.x,vector(0,0,1),nullvector);
	phcon_setparams2(gcon,vector(-360,360,0),nullvector,nullvector);
	gondela_ph = my;
}

action fun_sp ()
{
	var con;
	VECTOR aang;
	while(!gondela_ph) wait(1);
	phent_settype (my,PH_RIGID,PH_SPHERE);
	phent_setmass(my,1,PH_SPHERE);
	con = phcon_add(PH_HINGE,my,gondela_ph);
	
	//now find rotate axis 
	vec_set(aang,gondela_ph.x);vec_sub (aang,my.x);vec_normalize(aang,1);
	//
	phcon_setparams1(con,vector(my.x,my.y,gondela_ph.z),vector(aang.x,aang.y,0),nullvector);
	phcon_setparams2(con,vector(-360,360,0),nullvector,nullvector);
}
void main ()
{
	level_load ("map.wmb");
	ph_setgravity (vector(0,0,-300));
	while(!gondela_ph) wait(1);
	while (1)
	{
		phcon_setmotor (gcon,vector(3,50,0),nullvector,nullvector);
		wait(1);
	}
}

Posted By: Polypfreak1987

Re: Wave Swinger gondela - 04/18/09 13:36

Hello,

Thank you. You help me to the right position. But I have a (small?) problem. I have made some little changes in you script. (also in the sample you gave to me wich is still working great). But I have the following problem.

When I want to rotate the arm-entity (at your sample gondela_ph) the gondela's don't swing out the right way (See this link). They don't swing to the outside, but backwards (looks like the X-axis). This is the script right now, I use C-Script, not C-Lite.

Swinging gondela code
Code:
function swing_gondela() {
	var con;
	var aang[3];
	while(!molen_arm) {
		wait(1);
	}
	
	phent_settype(my,PH_RIGID,PH_SPHERE);
	phent_setmass(my,1,PH_SPHERE);
	con = phcon_add(PH_HINGE,my,molen_arm);
	
	vec_set(aang,molen_arm.x);
	vec_sub(aang,my.x);
	vec_normalize(aang,1);
	
	phcon_setparams1(con,vector(my.x,my.y,molen_arm.z),vector(aang.x,aang.y,0),nullvector);
	phcon_setparams2(con,vector(-360,360,0),nullvector,nullvector);
}


Arm-code
Code:
action molen {
	
	my.passable = on;
	
	phent_settype(my,PH_RIGID,PH_BOX);
	phent_setmass(my,1,PH_SPHERE);
	gcon = phcon_add(PH_HINGE,my,NULL);
	phcon_setparams1(gcon,my.x,vector(0,0,1),nullvector);
	phcon_setparams2(gcon,vector(-360,360,0),nullvector,nullvector);
	molen_arm = my;
}


Main-code at the bottom of the script.
Code:
function main()
{
	//laad het level
	level_load(level_str);
	ph_setgravity(vector(0,0,-3000));
	while(!molen_arm) {
		wait(1);
	}
	while(1) {
		phcon_setmotor(gcon,vector(3,10,0),nullvector,nullvector);
		
		wait(1);
	}
	//video_set(sys_metrics(0),sys_metrics(1),32,1);
}


I hope you can help me.

Thanks in advance.

Kind regards,

Polypfreak1987
Posted By: XD1v0

Re: Wave Swinger gondela - 04/18/09 20:01

so you using C-Script smirk , for me very difficult write on C-Script, but i try
there we go

Code:
entity* molen_arm;
var gcon;

action swing_gondela {
	var con;
	var aang[3];
	while(molen_arm==null) {
		wait(1);
	}
	
	phent_settype(my,PH_RIGID,PH_SPHERE);
	phent_setmass(my,1,PH_SPHERE);
	con = phcon_add(PH_HINGE,my,molen_arm);
	
	vec_set(aang,molen_arm.x);
	vec_sub(aang,my.x);
	vec_normalize(aang,1);
	vec_rotate(aang,vector(90,0,0));// there is error, i just forget rotate axis in previous code :p
	
	phcon_setparams1(con,vector(my.x,my.y,molen_arm.z),vector(aang.x,aang.y,0),nullvector);
	phcon_setparams2(con,vector(-360,360,0),nullvector,nullvector);
	
	//debug
	var pos[3];
	vec_set(pos,vector(my.x,my.y,molen_arm.z));
	while (1)
	{
		vec_set(aang,pos);vec_rotate(aang,molen_arm.pan);
		draw_line3d(aang,NULL,100);draw_line3d(my.x,vector(0,0,255),100);
		wait(1);
	}
}


action molen {
	
	my.passable = on;
	
	phent_settype(my,PH_RIGID,PH_BOX);
	phent_setmass(my,1,PH_SPHERE);
	gcon = phcon_add(PH_HINGE,my,NULL);
	phcon_setparams1(gcon,my.x,vector(0,0,1),nullvector);
	phcon_setparams2(gcon,vector(-360,360,0),nullvector,nullvector);
	molen_arm = my;
	
	
}
function main ()
{
	level_load ("map.wmb");
	ph_setgravity (vector(0,0,-300));
	while(molen_arm==null) {wait(1);}
	while (1)
	{
		phcon_setmotor (gcon,vector(3,10,0),nullvector,nullvector);
		wait(1);
	}
}

Posted By: Polypfreak1987

Re: Wave Swinger gondela - 04/19/09 05:59

Thank you very much. That did it. It works. laugh
© 2024 lite-C Forums