2 registered members (Akow, tomaslolo),
1,536
guests, and 12
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Portals + teleport weapon
#129712
05/14/07 06:47
05/14/07 06:47
|
Joined: Mar 2007
Posts: 776 Poor village - Poland ;)
tompo
OP
User
|
OP
User
Joined: Mar 2007
Posts: 776
Poor village - Poland ;)
|
My first post in showcase I hope You'll like it and waitng for replys/suggestions. I've made it just for fun not to use in game so don't look at graphic, modeling, effects, shaders...etc because You will not find them Link
Never say never.
|
|
|
Re: Portals + teleport weapon
[Re: mk_1]
#129714
05/14/07 07:36
05/14/07 07:36
|
Joined: Jun 2002
Posts: 1,017 Germany, Munich
Alex J.
Serious User
|
Serious User
Joined: Jun 2002
Posts: 1,017
Germany, Munich
|
this is really really really cool but why do i stand on the ground when the second portal is on the top of the wall? greetings
wer ziellos herumirren will, sollte der gro�en Masse folgen! ICQ: 159960451
|
|
|
Re: Portals + teleport weapon
[Re: tompo]
#129718
05/16/07 11:59
05/16/07 11:59
|
Joined: Mar 2007
Posts: 776 Poor village - Poland ;)
tompo
OP
User
|
OP
User
Joined: Mar 2007
Posts: 776
Poor village - Poland ;)
|
Source cod of'course simple one without particle effects, shaders... just portals I hope it'll work You may f.e. not closing portals to create nice loop when enemy is falling and fallig and falling... Have fun Code:
///////////////////////////////////////////// /////////| Portals script |////////////////// //////| as always free to use ;) |///////// ///////////////////////////////////////////// //| TomPo |///////////////| 12-05-'07 |// /////////////////////////////////////////////
/* Main idea of portals: (of'course main idea so probably not the best one) ;) - 2 cameras, 2 portals - camera_1 is at portal_1 position but displaying on portal_2 and vice versa - camera_1 (displaying on portal_2) is looking at the same direction as portal_1 - so looking at portal_1 we can see what the portal_2 is seeing - every portal has own "helper" (var) looking at him - so when we are lookig at portal we are changing pan of another camera by diff between us and the portal's helper we standing at becouse this second camera is dispaying on portal we are looking on, and we can see the changes - and finaly every portal has own exit to teleport player
Hints - use heigh resolution sprite's bmap like 1024x768 - to get better view quality - if you use models... skin them with heigh resolution bmap */
////////////////// VERIABLES ///////////////////////////// entity* portal_1; entity* portal_2; //nothing to explain var portals_count =0; //number of portals var portal_1_exit[3]; var portal_2_exit[3]; //place where player will go out var temp_ang_1; var temp_ang_2; //temp ang to calculate diferences between player and portal we looking at
////////////////// CAMERAS /////////////////////////// view camera {layer = 0; flags = VISIBLE;} view camera_portal_1 {layer = -1;arc = 60; aspect=0.5; size_x = 1024; size_y = 768;} view camera_portal_2 {layer = -1;arc = 60; aspect=0.5; size_x = 1024; size_y = 768;} //play with aspect to have a good ratio
////////////////////////////////////////////////////////////////////////////////////////////////// /*========================================= PORTAL START =======================================*/ //////////////////////////////////////////////////////////////////////////////////////////////////
///////////////// PORTALS ///////////////////////////
/// PORTAL 1 /////////////////////////////////////// function portal_1_fun { portal_1 = me; my.oriented = on; my.facing = off; my.passable = on; my.transparent = on; my.overlay = on; vec_add(my.x,normal); //move portal 1 quant away from wall/floor while(me) { if(vec_dist(my.x,player.x) < 200) //if player is close { if(portals_count == 1){wait(1);} //if only one portal do nothing else { vec_set(player.x,portal_2_exit.x); //teleport player to portal_2 player.pan = portal_2.pan; //turn him portals_count =0; //close portals } } if(portals_count ==0){portals_count =0; ent_remove(me); break;} //remove me if 0 portals wait(1); } }
//// PORTAL 2 /////////////////////////////////////// function portal_2_fun { portal_2 = me; my.oriented = on; my.facing = off; my.passable = on; my.transparent = on; my.overlay = on; vec_add(my.x,normal); while(me) { if(portal_1 != 0) //LETS FUN BEGIN... if portal_1 exist { vec_set(portal_1_exit, nullvector); portal_1_exit.x = 100; // set portal exit 100 quants from portal with vec_rotate(portal_1_exit, portal_1.pan); vec_add(portal_1_exit, portal_1.x);// the same direction vec_lerp(temp,portal_1_exit.x,portal_1.x,0.5); //place camera 50 quants away from portal vec_set(camera_portal_1.x,temp); // to avoid looking through the walls/floor temp_ang_1 = portal_1.pan + 180; // helper var with value oposit to portal pan "look at portal" vec_set(portal_2_exit, nullvector); portal_2_exit.x = 100; //the same with second exit,camera and helper vec_rotate(portal_2_exit, portal_2.pan); vec_add(portal_2_exit, portal_2.x); vec_lerp(temp,portal_2_exit.x,portal_2.x,0.5); vec_set(camera_portal_2.x,temp); temp_ang_2 = portal_2.pan + 180; camera_portal_1.bmap = bmap_for_entity(portal_2,0); //play what first portal "see" at second portal camera_portal_1.pan = portal_1.pan; //the same pan and tilt camera_portal_1.tilt = portal_1.tilt; camera_portal_1.visible = on; //make view visible camera_portal_2.bmap = bmap_for_entity(portal_1,0); //the same with second one camera_portal_2.pan = portal_2.pan; camera_portal_2.tilt = portal_2.tilt; camera_portal_2.visible = on; if(portal_1.tilt ==0)&&(portal_2.tilt ==0) //if portal is not on the floor or ceiling { camera_portal_2.tilt += camera.tilt; //camera_2 tilt has the same tilt what portal 2 + main camera tilt camera_portal_1.tilt += camera.tilt; camera_portal_2.pan -= (temp_ang_1 - player.pan); //camera_2 pan (viewing on portal_1) has the same pan as camera_portal_1.pan -= (temp_ang_2 - player.pan); //portal_2 and it's changing with diference between } // player pan and opposite pan of portal we looking at } if(portals_count ==0){portals_count =0; ent_remove(me);break;} wait(1); } } //////////// CREATE/CLOSE PORTALS ///////////////// function create_portal { temp.x = screen_size.x /2 ; temp.y = screen_size.y /2; temp.z = 10000; vec_for_screen(temp,CAMERA); //trace from middle of the screen to far away in deph view result = c_trace (camera.x, temp, IGNORE_ME | IGNORE_PASSABLE | IGNORE_SPRITES); portals_count +=1; //with LMB add one portal //create portal at traced target and pan/tilt him with wall/floor etc if(portals_count == 1){you=ent_create("portal_mdl.mdl",target.x,portal_1_fun); vec_to_angle(you.pan,normal);} if(portals_count == 2){you=ent_create("portal_2_mdl.mdl",target.x,portal_2_fun); vec_to_angle(you.pan,normal);} //if two portals in level, close them, wait 1 to avoid empty pointers and create firs portal if(portals_count > 2){portals_count =0;wait(1);create_portal();} }
function close_portals { portals_count = 0; //close portals }
//////////////// KEYS ///////////////////////////// on_mouse_left = create_portal; on_mouse_right = close_portals;
///////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////// END /////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////
Last edited by tompo; 05/16/07 14:15.
Never say never.
|
|
|
Re: Portals + teleport weapon
[Re: tompo]
#129719
05/16/07 13:41
05/16/07 13:41
|
Joined: Mar 2007
Posts: 776 Poor village - Poland ;)
tompo
OP
User
|
OP
User
Joined: Mar 2007
Posts: 776
Poor village - Poland ;)
|
And if You like my "see through walls" engine... Here You are It probably could be done easyer and faster... Code:
///////////////// // Portal door // // by TomPo ///// /////////////////
entity* door_portal; var portal_door_exit[3]; var moved =0; var my_top[3]; var dist_1; var dist_2; var dist_dif;
view camera_door {layer = -1;arc = 60; aspect=0.5; size_x = 1024; size_y = 768;} /////////////////// PORTAL "DOOR" /////////////////////////////////////
function door_portal { door_portal = me; my.passable =on; my.invisible = on; while(1) { if(mouse_right == 1) //while RMP is pressing { //trace from center of the screen and place portal at target temp.x = screen_size.x /2 ; temp.y = screen_size.y /2; temp.z = 10000; vec_for_screen(temp,CAMERA); result = c_trace (camera.x, temp, IGNORE_ME | IGNORE_PASSABLE | IGNORE_SPRITES); vec_set(my.x,target.x); vec_to_angle(my.pan,normal); vec_add(my.x,normal); my.invisible = off; //make me visible vec_set(portal_door_exit, nullvector); portal_door_exit.x = -100; //set my exit 100 quants vec_rotate(portal_door_exit, my.pan); vec_add(portal_door_exit, my.x); //behind me (in the next room) vec_set(camera_door.x,portal_door_exit.x); //place camera at the same position camera_door.bmap = bmap_for_entity(me,0); //play on me temp = door_portal.pan + 180; //camera pan is opposit to portal pan camera_door.pan = (temp - camera.pan) *2; //changing pan by moving main camera vec_set(temp, nullvector); temp.x = -5000; //trace far behind portal vec_rotate(temp, my.pan); vec_add(temp, my.x); result = c_trace (camera_door.x, temp, IGNORE_ME | IGNORE_PASSABLE | IGNORE_SPRITES); if(result != 0){camera_door.visible = on;} //if something is behind then show it if(result == 0){my.invisible = on; camera_door.visible = off;} //else close door_portal if(my.tilt != 0){my.invisible =on;} //or if I'm not on the wall close me too if(mouse_left == 1) //while pressing RMB press LMB { if(moved == 0) //if player haven't been moved { if(result != 0) //if another room exist { moved = 1; //player is moving vec_set(player.x,portal_door_exit.x); //teleport player } if(result == 0) //if another room doesn't exist { moved = 1; //player is moving if(my.tilt == 0) //if I'm at the wall { vec_set(temp, nullvector); temp.x = 200; vec_rotate(temp, my.pan); vec_add(temp, my.x); vec_set(player.x,temp); // place player 200 quants front of me player.pan = my.pan; //change player pan to portal pan } else //if I'm not on the wall { vec_set(player.x,my.x); //set player position at my position } } } } if(mouse_left == 0) //to avoid loop with teloporting { moved = 0; //if release LMB player is ready to next teleport } vec_set(temp, nullvector); temp.x = -5000; //trace from my center vec_rotate(temp, my.pan); vec_add(temp, my.x); c_trace (my.x, temp, IGNORE_ME | IGNORE_PASSABLE | IGNORE_SPRITES); dist_1 = vec_dist(my.x, target.x); //distance from my center to traced hit (=1) vec_for_vertex(my_top,me,16); //set where is my top (I used a model and vertex #16 was the upper one) c_trace (my_top, temp, IGNORE_ME | IGNORE_PASSABLE | IGNORE_SPRITES); //trace from my top dist_2 = vec_dist(my_top, target.x); //distance from my top to traced hit dist_dif = dist_2 - dist_1; //if distance between traced from center and traced from top if(dist_dif > 200){my.invisible = on;} // is bigger than f.e. 200 it means that I'm on the edge so don't display me } if(mouse_right == 0) //if RMB is no longer pressing { my.invisible = on; my.alpha = 0; //close portal camera_door.visible = off; }
wait(1); } }
function create_portal_door //create only once { you = ent_create("portal_door.mdl",my.x,door_portal); }
Last edited by tompo; 05/16/07 14:10.
Never say never.
|
|
|
Re: Portals + teleport weapon
[Re: tompo]
#129720
05/16/07 16:10
05/16/07 16:10
|
Joined: Oct 2006
Posts: 873
Shadow969
User
|
User
Joined: Oct 2006
Posts: 873
|
Thanx, that's a very generous contribution, gonna check it As i see currently it can only teleport player, maybe i'll try to enhance it a little so it will teleport everything i guess that'll be fun It's a pity that i don't have PRO...i hope A7 will come out soon
Last edited by Shadow969; 05/16/07 16:16.
|
|
|
Re: Portals + teleport weapon
[Re: Shadow969]
#129721
05/16/07 17:13
05/16/07 17:13
|
Joined: Mar 2007
Posts: 776 Poor village - Poland ;)
tompo
OP
User
|
OP
User
Joined: Mar 2007
Posts: 776
Poor village - Poland ;)
|
for teleporting something else than player just write in portal_1 if dist my.x you.x < 200 in f.e. trigger event
Last edited by tompo; 05/16/07 17:58.
Never say never.
|
|
|
|