Gamestudio Links
Zorro Links
Newest Posts
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
1 registered members (TedMar), 1,420 guests, and 3 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
Using Vectors to provide a custom collision detection #10007
08/05/02 04:19
08/05/02 04:19

A
Anonymous OP
Unregistered
Anonymous OP
Unregistered
A



I did my research here, and this is what im asking for help with. I want to program the custom collsion detection, not to the extent of a bunch of polygons, but take this example and then look at my psueado code below:

The player is walking and hits a force field in the shape of a star, using WED blocks, i could put an invisible block there or, using C-Script I could program the collsion detection. However, i don't want to edit any of my levels, and want all of the effects to be script driven.

Ok, you can basically make collsion detection in levels by using invisible blocks, or you could use something like this:

IF ((player.X > collison_point_min.X) && (player.X < collsion_point_max.X)) {
IF ((player.Y> collison_point_min.Y) && (player.Y < collsion_point_max.Y)) {
// here we would block the player from going any further.
}
}

While this would in theroy work for straight lines that are at 90* angles with other lines, or rectangles, what about coding a collsion detection for a triangular area. My thoughts on this use something like vec_subtract(collsion_point_min.X,collsion_point_max.X) and checking if the player was in that area. But, i have no clue as what the actual coding would look like. I'll continue to look up and try stuff from the manual, and if i figure it out, i'll post it here, for the time being if anyone has any clues as to how i could do this, please without any code i would greatly appreciate it. I gotta figure this out myself.

If you need a better description on this subject let me know.

-NI

Re: Using Vectors to provide a custom collision detection #10008
08/05/02 07:36
08/05/02 07:36
Joined: Jun 2002
Posts: 248
NZ
mudhole Offline
Member
mudhole  Offline
Member

Joined: Jun 2002
Posts: 248
NZ
I'd actually suggest that you use invisible blocks. They will provide faster and better collision detection than just about anything you could code in C-Script. They would offer the advantage of: gliding along force fields, hull instead of single point collision detection, much, much easier.

Having said that though, if you want to go ahead and code it - good for you. To test if a point is inside a convex polygon of any shape and number of sides, just add up the angles the point makes with the vertices of the polygon. If the result is pretty damn close to 360 degrees, the point is inside the polygon. If not, the point is outside.

For a concave polgon like a star, you would have to break it up into convex geometry like triangles for the points, and a pentagon in the center.

For a single convex (n vertices) polygon, heres what the algorithm would look like:

code:
// make a vector from the point to the 1st vertex
// make a vector from the point to the 2nd vertex
// calculate the angle betweent the two vectors
// add this angle to a running sum
// repeat for the 2nd & 3rd vertices, 3rd & 4th...... nth & 1st

// if abs(angle-360) < some small number, the point is inside
// otherwise, it is not



Re: Using Vectors to provide a custom collision detection #10009
08/05/02 13:27
08/05/02 13:27

A
Anonymous OP
Unregistered
Anonymous OP
Unregistered
A



hey, thanks for the help, that helped a lot, now if you want to know what you just helped me with, you'll see pictures soon, because now im the first person (to my knowledge) to construct a demo a Resident Evil Simulation with 3DGS. Although still kinda buggy, it works.

-NI


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