Gamestudio Links
Zorro Links
Newest Posts
Z9 getting Error 058
by k_ivan. 04/25/26 19:13
ZorroGPT
by TipmyPip. 04/25/26 16:09
Stooq now requires an API key
by jcl. 04/13/26 09:42
Strange "Alien" Skull created with >Knubber<
by NeoDumont. 04/10/26 18:58
400 free seamless texture pack downl. here !
by NeoDumont. 04/08/26 19:55
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
0 registered members (), 3,106 guests, and 27 spiders.
Key: Admin, Global Mod, Mod
Newest Members
valino, juergenwue, VladMak, Geir, ondrej
19209 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Check If Collide With Object? #368784
04/28/11 12:35
04/28/11 12:35
Joined: Apr 2011
Posts: 12
Sweden
L
Linus371 Offline OP
Newbie
Linus371  Offline OP
Newbie
L

Joined: Apr 2011
Posts: 12
Sweden
How do I make something check if it is colliding with a serten thing? Like if my car collides with the goal, It loads a new level ex?
How could I do that? laugh

Re: Check If Collide With Object? [Re: Linus371] #368786
04/28/11 12:43
04/28/11 12:43
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
The most simple thing is a function that checks the distant between goal and the car.
If it is in the function attached to the goal, it can look like this:

function goal()
{
while(1)
{while(player == NULL){wait(1);}//assure that the entity with the pointer player is already in the level
if(vec_dist(me, player) < 100)//me is the pointer of the goal, player is the pointer of your car
{
... //put in load next level or whatever you want
}
wait(1);
}
}

You have to put 'player = me;' into the function of your car

Re: Check If Collide With Object? [Re: Pappenheimer] #368788
04/28/11 13:07
04/28/11 13:07
Joined: May 2009
Posts: 5,377
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,377
Caucasus
Collusion can be checked with events.


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Check If Collide With Object? [Re: 3run] #368792
04/28/11 14:02
04/28/11 14:02
Joined: Apr 2011
Posts: 12
Sweden
L
Linus371 Offline OP
Newbie
Linus371  Offline OP
Newbie
L

Joined: Apr 2011
Posts: 12
Sweden
This is my final code after I did that thing to check how close it was:
Code:
ENTITY* playerCar;

action dumper(){
	playerCar=me;
	var speed = 4; // Var för bilens fart
	var turn_speed = 7; // Var för turn speed
	var grav = -7; //Var för Gravitation
	
	// Sparar start positioner så att dom kan reseter seneare!
	var startX=me.x;
	var startY=me.y;
	var startZ=me.z;
	var startPan=me.pan;
	
	// Annat Setup:
	camera.tilt=-50;
	my.ambient = 80;
	
	while (1){
		// Om man kör framåt:
		if (key_w){
			c_move(me,vector(speed * time_step,0,1*time_step),nullvector,GLIDE | IGNORE_FLAG2);
			if (key_a){
				my.pan+=turn_speed*time_step;
			}
			if (key_d){
				my.pan-=turn_speed*time_step;
			}
		}
		// Om man kör bakåt
		if (key_s){
			c_move(me,vector(-speed * time_step,0,1*time_step),nullvector,GLIDE | IGNORE_FLAG2);
			if (key_a){
				my.pan-=turn_speed*time_step;
			}
			if (key_d){
				my.pan+=turn_speed*time_step;
			}
		}
	// Gravitation :3
	c_move(me,nullvector,vector(0,0,(grav) * time_step),GLIDE | IGNORE_FLAG2 | IGNORE_ME);
	
	// Om man ramlar
	if (me.z<-200){
		// Reset Position
		me.x=startX;
		me.y=startY;
		me.z=startZ;
		me.pan=startPan;
	}
	// Flyttar kameran till rätt ställe >:3
	camera.x=me.x-180;
	camera.y=me.y;
	camera.z=my.z+280;
		
	wait(1);
	}
}

action goal(){
	while(1){
		while(playerCar == NULL){
			wait(1);
		}
		if(vec_dist(me, playerCar) < 500){
			level_load("leve2.wmb");
			wait(2);
		}
	wait(1);
	}
}


function main()
{
	level_load("mainLevel.wmb");
}



But when I get close it, Nothing happens!
What have I've done wrong? frown

Re: Check If Collide With Object? [Re: Linus371] #368795
04/28/11 14:10
04/28/11 14:10
Joined: Mar 2009
Posts: 88
Walori Offline
Junior Member
Walori  Offline
Junior Member

Joined: Mar 2009
Posts: 88
vec_dist(me, playerCar) one small mistake, vec_dist requires VECTOR's, now you're using ENTITY pointers, so change:

Original:
vec_dist(me, playerCar)

Modified:
vec_dist(me.x, playerCar.x)

Re: Check If Collide With Object? [Re: Walori] #368799
04/28/11 14:40
04/28/11 14:40
Joined: Apr 2011
Posts: 12
Sweden
L
Linus371 Offline OP
Newbie
Linus371  Offline OP
Newbie
L

Joined: Apr 2011
Posts: 12
Sweden
Originally Posted By: Walori
vec_dist(me, playerCar) one small mistake, vec_dist requires VECTOR's, now you're using ENTITY pointers, so change:

Original:
vec_dist(me, playerCar)

Modified:
vec_dist(me.x, playerCar.x)

Why me.x? Should I not check both z,x and y? :S
And If I use your modified code, It wont still work :C

Last edited by Linus371; 04/28/11 14:45.
Re: Check If Collide With Object? [Re: Linus371] #368801
04/28/11 15:16
04/28/11 15:16
Joined: Feb 2010
Posts: 320
TANA/Madagascar
3dgs_snake Offline
Senior Member
3dgs_snake  Offline
Senior Member

Joined: Feb 2010
Posts: 320
TANA/Madagascar
Hi,

Yes you are right, but that code is also right grin. me is an entity pointer, but you need to pass a VECTOR to the function, with Lite-C, you need to pass the first element of a vector and the next 2 elements will be taken automatically. The same goes for entity skills (ex:
Code:
vec_set(my.skill1, vector(1, 2, 3));

to set both skill1, skill2, and skill3), and entity rotation (you only need to pass the entity pan as a vector parameter of a function).

Hope you understand.

Best regards.

Re: Check If Collide With Object? [Re: 3dgs_snake] #368808
04/28/11 15:52
04/28/11 15:52
Joined: Apr 2011
Posts: 12
Sweden
L
Linus371 Offline OP
Newbie
Linus371  Offline OP
Newbie
L

Joined: Apr 2011
Posts: 12
Sweden
Originally Posted By: 3dgs_snake
Hi,

Yes you are right, but that code is also right grin. me is an entity pointer, but you need to pass a VECTOR to the function, with Lite-C, you need to pass the first element of a vector and the next 2 elements will be taken automatically. The same goes for entity skills (ex:
Code:
vec_set(my.skill1, vector(1, 2, 3));

to set both skill1, skill2, and skill3), and entity rotation (you only need to pass the entity pan as a vector parameter of a function).

Hope you understand.

Best regards.

Yeah... Thanks..
But Then that code you sent me should work?
But It don't! shocked

And is that skill1-3 a variable or something else? smirk

Re: Check If Collide With Object? [Re: Linus371] #368810
04/28/11 16:05
04/28/11 16:05
Joined: Feb 2010
Posts: 320
TANA/Madagascar
3dgs_snake Offline
Senior Member
3dgs_snake  Offline
Senior Member

Joined: Feb 2010
Posts: 320
TANA/Madagascar
grin Hi, that code I sent to you is an example. Just to explain you how you can use entity position, entity skills and entity rotation as vectors, that's all. skill1, skill2, ... skill100 are entities all purpose member variables (of var type), you can use them to store pointers to other objects or simply as variables or vectors.

Best regards.

Re: Check If Collide With Object? [Re: 3dgs_snake] #368820
04/28/11 17:40
04/28/11 17:40
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Sorry, in my code I mixed up a line with another.
This line:
{while(player == NULL){wait(1);}//assure that the entity with the pointer player is already in the level
has to be placed before the main while(1) loop.
Its task is to prevent the while loop from starting before the player pointer is valid.


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | 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