Post

 Resources 

Console

Home | Profile | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 VBGamer
 VBGamer
 2d Collision Sliding
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Jpez1432
Neophyte

6 Posts

Posted - Dec 01 2004 :  08:59:22 AM  Show Profile  Send Jpez1432 an AOL message  Reply with Quote
Hello, my name is James Pezold and I am a avid VB programmer. Alright, I have my VBDoom engine up and running and as most of you know someone by the name of Game_Maker uploaded a collision module for line/circle collisions. I have implemented it and have collisions but would like to have the circle slide along the line.... so if Game_Maker would reply or anyone else with knowledge of this I would be ever greatful.

sdw
Warrior

USA
160 Posts

Posted - Dec 01 2004 :  5:04:09 PM  Show Profile  Visit sdw's Homepage  Click to see sdw's MSN Messenger address  Reply with Quote
Can you explain what you mean by "slide along the line"?

Go to Top of Page

Jpez1432
Neophyte

6 Posts

Posted - Dec 01 2004 :  6:05:49 PM  Show Profile  Send Jpez1432 an AOL message  Reply with Quote
like in doom, when you walk into a wall at a angle it lets you slide against it.
Go to Top of Page

Eric Coleman
Gladiator

USA
811 Posts

Posted - Dec 02 2004 :  12:17:26 AM  Show Profile  Visit Eric Coleman's Homepage  Reply with Quote
Movement without collision detection is generally quite simple. You have an object or sprite, it has a velocity, and each frame you update it's postion with velocity * time elapsed.

When adding collision detection, you bascially add a check in the movement code to determine if a collision has occured. If it has, then you don't update the sprites' position, otherwise you do.

However, to have the object slide, you need to calculate the velocity vector's projection onto the collision surface. That becomes your new velocity vector for that frame's collision detection of other surfaces. To determine the projection of a vector on another vector is quite simple. Let V be your velocity vector, and P1 and P2 be the end points of the line segment. Then calculate V2 by subtracting P1 - P2. Then the projection of V onto V2 is just ((V dot V2) / Length(V2) ) * Normalized(V2).

Or in code terms.
D = v.x * v2.x + v.y * v2.y = V dot V2
L = sqr(v2.x^2 + v2.y^2) = Length(v2)
v2.x = v2.x / L ' Normalized vector.
v2.y = v2.y / L
V2.x = V2.x * D / L
V2.y = V2.y * D / L


In psuedo code
  
Get Applied Velocity  
For Each Surface To Collide With
   Calculate Projected Velocity, Velocity Projected onto Collision Surface.  
   Velocity = Projected Velocity  
Next
Move Object by Calculated Velocity * elapsed time for frame.  
  


The thing to note is that the projected velocity is a temporary value that's calculated each frame, unless of course you want walls to stop you, Otherwise when you're calculating the projected velocity make sure you don't ever overwrite the original velocity of the sprite.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
VBGamer © Go To Top Of Page
This page was generated in 0.1 seconds. Snitz Forums 2000

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.