Gamestudio Links
Zorro Links
Newest Posts
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
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (degenerate_762, AbrahamR, AndrewAMD, ozgur), 667 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
C-script help #254168
03/01/09 15:14
03/01/09 15:14
Joined: Feb 2006
Posts: 616
Netherlands
cartoon_baboon Offline OP
User
cartoon_baboon  Offline OP
User

Joined: Feb 2006
Posts: 616
Netherlands
Hi,
I'm working on a quick prototype for a project at college.

I'm hoping someone can help me to get the following thing working as I can't seem to figure it out:

The game is played first person. There is an object in the environment and when the player presses a key I want to have that object follow the player around while keeping it's relative location to the player the same (ie if the player sees the object in the center of the screen it should remain visible at the center of the screen while the player walks around)

Thanks!

cartoon_baboon

Re: C-script help [Re: cartoon_baboon] #254174
03/01/09 15:35
03/01/09 15:35
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Code:
var status_CarryObject = 0;

action object_act
{
  var attached;
  var offset[3];
  
  attached = 0;

  while(me)
  {
    if(status_CarryObject)
    {
      if(attached == 0)
      {
        vec_diff(offset,player.x,my.x);
        attached = 1;
      }
      vec_set(my.x,offset.x);
      vec_add(my.x,player.x);
    }
    else { attached = 0; }
    wait(1);
  }
}

Attention: not tested, if it blows up your machine its your fault wink
Something along that line should work though

edit:
add the else status so now you should also be able to re-pick up that object.

edit #2:
forgot to mention: To use this you need a function which sets that status_CarryObject var to one on key press.
If you want several objects being carried individually you have to use c_scan plus scan_events, but because you were talking only about one object I went the easy way wink

Last edited by Xarthor; 03/01/09 15:39.
Re: C-script help [Re: Xarthor] #254199
03/01/09 17:47
03/01/09 17:47
Joined: Feb 2006
Posts: 616
Netherlands
cartoon_baboon Offline OP
User
cartoon_baboon  Offline OP
User

Joined: Feb 2006
Posts: 616
Netherlands
Hi,

thanks a lot for the help, this is a good start but the code doesn't do exactly what it should wink

firstly when the key is pushed the object doesn't stay in it's original position, instead it jumps to a position exactly on the opposite side of the player.

Also, though the object follows the player around correctly it doesn't take it's pan into account. The idea is that the if the object is in front of me when the button is pushed that it remains in front of me when I walk around(and look around, which I didn't specify in my original post)

Hopefully you could take another look at the code to see what needs to be adjusted.

Thanks in advance!

Re: C-script help [Re: cartoon_baboon] #254218
03/01/09 19:24
03/01/09 19:24
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Ok I wrote myself a small test app to find a working solution and finally I found on:
Code:
action object_act
{
	var attached;
	var offset_dist[3];
	var offset_angle[3];
	
	attached = 0;
	
	while(!player) { wait(1); }
	
	while(my)
	{
		if(status_CarryBox)
		{
			if(attached == 0)
			{
				offset_angle[0] = player.pan;
				offset_angle[1] = 0;
				offset_angle[2] = 0;
				
				offset_dist.x = my.x - player.x;
				offset_dist.y = my.y - player.y;
				offset_dist.z = 0;
				
				attached = 1;
			}
			
			my.pan = player.pan;
			
			vec_set(my.x,offset_dist.x);
			vec_diff(temp,player.pan,offset_angle);
			vec_rotate(my.x,temp);
			vec_add(my.x,player.x);
		}
		else
		{
			attached = 0;
		}
		
		wait(1);
	}
}


This code only takes the pan angle into consideration and the .z position is not altered as well.
I hope this is what you were looking for.

Re: C-script help [Re: Xarthor] #254224
03/01/09 19:59
03/01/09 19:59
Joined: Feb 2006
Posts: 616
Netherlands
cartoon_baboon Offline OP
User
cartoon_baboon  Offline OP
User

Joined: Feb 2006
Posts: 616
Netherlands
Thanks alot!!! That did the trick!

cartoon_baboon

Re: C-script help [Re: cartoon_baboon] #255137
03/07/09 21:48
03/07/09 21:48
Joined: Feb 2006
Posts: 616
Netherlands
cartoon_baboon Offline OP
User
cartoon_baboon  Offline OP
User

Joined: Feb 2006
Posts: 616
Netherlands
Well here I am again, in need of some help once more wink

I wanted to include a new feature and I hoped I'd be able to adjust the code Xarthor made myself to get it working but no such luck.

Basically what I need is for the computer to calculate the relative distance and angle of the player to object 1 (see the beuatifully drawn example below). Then the block has to be placed relative to the player just as the player is relative to object 1.

Example:
The player is standing infront of object 1 than the block will be infront of the player. If the player than turns around but doesn't move the block will remain in the center of the player's view.


Really hope someone (Xarthor? wink ) can help with this.

Thanks!

cartoon_baboon

Re: C-script help [Re: cartoon_baboon] #255161
03/08/09 10:16
03/08/09 10:16
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Just to make this more clear:
You want to place that block accordingly to the angle from the player to that object1 which is not the block?
And it changes only its position if the player moves but not if he just turns?

Re: C-script help [Re: Xarthor] #255162
03/08/09 10:24
03/08/09 10:24
Joined: Feb 2006
Posts: 616
Netherlands
cartoon_baboon Offline OP
User
cartoon_baboon  Offline OP
User

Joined: Feb 2006
Posts: 616
Netherlands
Hi,
thanks for the reply.

Quote:
You want to place that block accordingly to the angle from the player to that object1 which is not the block?

yes, that's correct.

Quote:
And it changes only its position if the player moves but not if he just turns?

This isn't quite correct. When the player moves it's relative distance and angle to object one changes so yes, then the block has to change it's posistion as well. But when the player turns the block has to move as well to keep itself at the right angle to the player (for example, the block was in front of the player, then if the player was to turn the block has to kepe itself infront of the player)

Thanks for taking the time to help with this.

cartoon_baboon

Re: C-script help [Re: cartoon_baboon] #255253
03/09/09 08:15
03/09/09 08:15
Joined: Feb 2006
Posts: 616
Netherlands
cartoon_baboon Offline OP
User
cartoon_baboon  Offline OP
User

Joined: Feb 2006
Posts: 616
Netherlands
Well I managed to edit the code to get it to place the cube at the right position (see below). Problem is it only calculates everything once. So when I move and turn the player the cube stays at it's original position. I've tried to get it to update constantly, though it then manages to follow the player around it doesn't recalculate the offset and angle between the player and "objent".

How should I edit it this code to get it do do that?


Code:
	var attached;
	var offset_dist[3];
	var offset_angle[3];
  var attached = 0;
  
  	while(!player) { wait(1); }
		if(status_CarryBox)
    {
    	
      if(attached == 0)
      {
				offset_angle[0] = objent.pan;
				offset_angle[1] = 0;
				offset_angle[2] = 0;
				
				offset_dist.x = (player.x-objent.x);
				offset_dist.y = (player.y-objent.y);
				offset_dist.z = 0;
        attached = 1;
       
      }
my.pan = player.pan;
			
			vec_set(my.x,offset_dist.x);
			vec_diff(temp,player.pan,offset_angle);
			vec_rotate(my.x,temp);
			vec_add(my.x,player.x);
			


			
    }


Thanks!

cartoon_baboon

Last edited by cartoon_baboon; 03/09/09 08:19.
Re: C-script help [Re: cartoon_baboon] #255400
03/10/09 08:20
03/10/09 08:20
Joined: Feb 2006
Posts: 616
Netherlands
cartoon_baboon Offline OP
User
cartoon_baboon  Offline OP
User

Joined: Feb 2006
Posts: 616
Netherlands
Any attempts at getting the code to recalculate the offset_dist etc by using while loops results in a rather odd flickering etc but still doesn't do what is needed.

Anybody who can help?

cartoon_baboon

Page 1 of 2 1 2

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