Graal Forums  

Go Back   Graal Forums > Development Forums > Future Improvements
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-30-2005, 02:44 PM
Kaimetsu Kaimetsu is offline
Script Monkey
Kaimetsu's Avatar
Join Date: May 2001
Posts: 18,222
Kaimetsu will become famous soon enough
Vector-Based Collision

Onwall2 is more or less sufficient for the simple movement of player characters, since they tend to travel at consistent speeds and they can be considered rectangular. However, it is pretty lacking for many other types of collision detection. Rotatable objects are a pretty good example: Rotate a square by thirty degrees and then fire it in an arbitrary direction. Odds are it won't be easy to write fast, reliable code to find out what it'll hit first.

It would be nice, then, to have a function like this:

vectorcollision({line1},{line2},time)

The two lines represent the start and end state of a single vector. It changes linearly from one to the other over a specified time (in most cases we would pass 0.05). The engine examines the path of this vector and determines if/when it will first collide with a blocking object. Then it returns the coordinates and relative time of that collision (we can return arrays, right?).

Alternatively,

vectorcollision({line},dx,dy,drotation,speed)

dx,dy give the velocity of the centre of the line. drotation gives its rate of spin (adjusted to be consistent with the velocity). Again, the engine figures out when and where the lines collides with something and returns its prediction.
__________________
Reply With Quote
  #2  
Old 03-31-2005, 01:31 AM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
Ah that sounds quite complicated. It is planned that there will be some basic vector collision detection for showimgs (clientside-games/effects), but I don't see the reason for npcs or similar. The problem is that you have many moving objects of different shape, a rectangle check or radius check is most of the time the only working way, easy to configure and fast to calculate. I am open to new ideas though, if you have some examples where a better collision detection would help a lot then please post them.
Reply With Quote
  #3  
Old 03-31-2005, 02:05 AM
Kaimetsu Kaimetsu is offline
Script Monkey
Kaimetsu's Avatar
Join Date: May 2001
Posts: 18,222
Kaimetsu will become famous soon enough
Well, I'm mostly thinking about vehicles. Like one time I was coding a car for Era, and it had sprites for sixteen different directions. I wanted to add a nice physics system too, but that required some very precise collision detection. If we were just dealing with tiles then it wouldn't be so bad, but I also have to consider players and weird-shaped NPCs and suchlike.

So, what're my options? The best approach I can imagine is to treat the car as a rectangle and divide it into four sides, and then figure out when each of them will intersect with other stuff in the level. But the only precise way to do that is to iterate through every pixel, or build up a geometrical summary of the shape of the level. In either case, it'd be much faster and easier if hardcoded.

Check out the image I attached. It gives a basic summary of my problem.
Attached Thumbnails
Click image for larger version

Name:	car.PNG
Views:	257
Size:	6.1 KB
ID:	31520  
__________________
Reply With Quote
  #4  
Old 04-08-2005, 02:56 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
Ok I understand, don't know why the function should care about the rotation of the colliding line though, since movements must be linear anyway (by setting positions explicitely or using the move command).
The simpliest way would probably be to just check for the tiles by script (several onwall checks along the line in steps of 1 tile). That way you can also theoretically detect diagonal walls. I can add some command for easier collision detection though, but it should be made so that it can be used for many different cases of collision.
Reply With Quote
  #5  
Old 04-08-2005, 03:45 PM
Kaimetsu Kaimetsu is offline
Script Monkey
Kaimetsu's Avatar
Join Date: May 2001
Posts: 18,222
Kaimetsu will become famous soon enough
Quote:
Originally Posted by Stefan
Ok I understand, don't know why the function should care about the rotation of the colliding line though, since movements must be linear anyway
Well, moving linearly from point A to point B between two frames is just an approximation to a smooth, continuous motion. There'd be a difference between a curved path and a linear one, even if it's relatively small.

Quote:
The simpliest way would probably be to just check for the tiles by script (several onwall checks along the line in steps of 1 tile). That way you can also theoretically detect diagonal walls
Yeah, it kind of works, but you can't get much precision unless you use dozens of checks. Recently I made a little system that scans through the level and builds an array of vectors representing walls (like, if there were a bush in a level then it would define a wall vector for each of its sides). Then I used some fairly simple vector calculations to find out exactly where and when a collision would occur between a wall and a moving object. It's very fast and extremely precise, but it can't handle dynamic objects (players, movable tiles, etc) or NPCs with weird shapes. It's really only good for minigames.

Out of curiosity, how does collision detection work in Graal3D? I haven't had a chance to play with its scripting engine yet
__________________
Reply With Quote
  #6  
Old 04-10-2005, 01:51 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
Quote:
Originally Posted by Kaimetsu
Yeah, it kind of works, but you can't get much precision unless you use dozens of checks. Recently I made a little system that scans through the level and builds an array of vectors representing walls (like, if there were a bush in a level then it would define a wall vector for each of its sides). Then I used some fairly simple vector calculations to find out exactly where and when a collision would occur between a wall and a moving object. It's very fast and extremely precise, but it can't handle dynamic objects (players, movable tiles, etc) or NPCs with weird shapes. It's really only good for minigames.
Would be interesting to see that script We plan to soon add an automatic movement and collision system for showimgs for making client-side games. For serverside it could be interesting to add more shape modes for the setshape command (circle, oval, centered box) and make a function for knowing with which objects the npc/player collides if moved along a specified vector, with options for which objects should be handled (only npcs, only players, only tiles etc.) and returning the impact position, the distance the npc moved, and eventually the collision normal or reflection vector.

Quote:
Originally Posted by Kaimetsu
Out of curiosity, how does collision detection work in Graal3D? I haven't had a chance to play with its scripting engine yet
It is using the polygons of the objects and is handled by engine. It is taking the polygons of the player and the velocity, and is colliding it against near objects, getting the polygon that touches the thing and the distance. Currently it is not very fast though, so it's basicly taking a box for the players. Only the interior objects (houses, caves) have are more optimized collision detection and use all polygons for collision detection. We will need to change that sometime, to use better collision libraries and make the player movement completely scripted.
Reply With Quote
  #7  
Old 04-11-2005, 05:01 AM
Googi Googi is offline
A Serious Epidemic
Googi's Avatar
Join Date: Oct 2001
Location: Canada
Posts: 18,866
Googi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud ofGoogi has much to be proud of
Send a message via AIM to Googi
Would it work online?
__________________
Reply With Quote
  #8  
Old 04-11-2005, 07:19 AM
Kaimetsu Kaimetsu is offline
Script Monkey
Kaimetsu's Avatar
Join Date: May 2001
Posts: 18,222
Kaimetsu will become famous soon enough
Quote:
Originally Posted by Stefan
Would be interesting to see that script
Okay. I attached it to this post.

As a sidenote: It would be nice if there were an event that triggers on the clientside when the board is updated (if there isn't already - I'm a little out of the loop). Since my script just scans the level once when the player enters, it can't deal with changes like when somebody picks up a bush.

Quote:
We plan to soon add an automatic movement and collision system for showimgs for making client-side games
Hm, sounds like a good idea. If it were my decision, I think I'd just add a single function that takes two images and their positions and tells the script whether or not they intersect. Then it'd be pretty easy to work into minigames, but it would also be flexible enough to use for other applications (like, if you want to check a possible collision without actually drawing an image).

Quote:
For serverside it could be interesting to add more shape modes for the setshape command (circle, oval, centered box) and make a function for knowing with which objects the npc/player collides if moved along a specified vector, with options for which objects should be handled (only npcs, only players, only tiles etc.) and returning the impact position, the distance the npc moved, and eventually the collision normal or reflection vector
That sounds pretty good. Maybe also some way to define the shape and rotation of the player?

Quote:
It is using the polygons of the objects and is handled by engine. It is taking the polygons of the player and the velocity, and is colliding it against near objects, getting the polygon that touches the thing and the distance
Hm, that raises an interesting point. Does G3D use varying LOD meshes? If there were a simpler mesh used purely for collision, it'd probably make things a little faster.

Quote:
We will need to change that sometime, to use better collision libraries and make the player movement completely scripted.
Yeah, sounds like a pretty significant improvement. I had a rough design for a G3D playerworld, but it wouldn't work unless I had a large amount of control over the player's movement.

Quote:
Originally Posted by Googi
Would it work online?
My vector thing? Yeah, I guess. But it's not very useful in its current state.
Attached Files
File Type: zip vectorlevel.zip (2.2 KB, 180 views)
__________________
Reply With Quote
  #9  
Old 04-11-2005, 06:44 PM
Benm00t Benm00t is offline
I made a tree!
Benm00t's Avatar
Join Date: Jul 2003
Location: The Intarwebbernetwork!
Posts: 987
Benm00t is on a distinguished road
oo, sorry for treating it like a toy but thats kinda fun to play with. Also, i seemed to notice a bug, which i think is more to do with the program, than the script.

I ran Graal, clicked on "Offline test" instead of editor. Ah well, just open it using this anyway. Used F5, found the level, and when it opened, all the tiles were all funky, and it seems the script then works incorrectly as it is finding non blocking tiles. See image 1.

If you open the level from the editor, or go into the level editor and run the level again, then it works fine. See image 2.
Attached Thumbnails
Click image for larger version

Name:	zomg1.png
Views:	229
Size:	29.2 KB
ID:	31641   Click image for larger version

Name:	zomg2.png
Views:	203
Size:	26.4 KB
ID:	31642  
__________________
Lag is a good thing. Only those without it complain.

~ Ben
Reply With Quote
  #10  
Old 04-11-2005, 06:57 PM
Kaimetsu Kaimetsu is offline
Script Monkey
Kaimetsu's Avatar
Join Date: May 2001
Posts: 18,222
Kaimetsu will become famous soon enough
Quote:
Originally Posted by Benm00t
I ran Graal, clicked on "Offline test" instead of editor. Ah well, just open it using this anyway. Used F5, found the level, and when it opened, all the tiles were all funky
Yeah, that's pretty strange. Still, my script doesn't set the tiles at any point - it merely checks the onwall status of each 16x16 block in the level. I can only assume that it's some unintended behaviour in the client.
__________________
Reply With Quote
  #11  
Old 04-11-2005, 07:05 PM
Rick Rick is offline
PipBoy Extraordinaire!
Rick's Avatar
Join Date: Jul 2004
Location: Long Beach, California.
Posts: 831
Rick is on a distinguished road
That's because the offline mode uses GK tileset.
Reply With Quote
  #12  
Old 07-05-2005, 06:09 AM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
I'm reviving a dead thread here, but it's not really in vain, I'd think. Vector-based collision would be a very good idea. I am actually working on a cliff-jumping script right now, and it would be a lot nicer if I could make it a diaganol parallelogram shape for the players to touch, rather than 9 or 10 (16x16) setshaped squares for the diagonal ledges.
Reply With Quote
  #13  
Old 07-05-2005, 06:57 AM
Rick Rick is offline
PipBoy Extraordinaire!
Rick's Avatar
Join Date: Jul 2004
Location: Long Beach, California.
Posts: 831
Rick is on a distinguished road
There are vector related functions in v4. I havn't played with them yet though.
Reply With Quote
  #14  
Old 07-05-2005, 06:59 AM
Kaimetsu Kaimetsu is offline
Script Monkey
Kaimetsu's Avatar
Join Date: May 2001
Posts: 18,222
Kaimetsu will become famous soon enough
Quote:
Originally Posted by Rick
There are vector related functions in v4. I havn't played with them yet though.
Presumably just basic stuff like cross products, normalisation, etc.
__________________
Reply With Quote
  #15  
Old 07-05-2005, 04:03 PM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
I still use v2. Anways, what I mean is to be able to shape stuff like a diagonal parallelogram. Right now what I have to do for diaganol walls is like (see attached). It would make a lot more sense to be able to have diagonal shapes for something like this.
Attached Thumbnails
Click image for larger version

Name:	diaganoljump.png
Views:	191
Size:	59.1 KB
ID:	32680  
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 09:49 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.