Post

 Resources 

Console

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

 All Forums
 VBGamer
 VBGamer
 2d Collision Sliding

Note: You must be registered in order to post a reply.

Screensize:
UserName:
Password:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkInsert EmailInsert Image Insert CodeInsert QuoteInsert List Spell Checker
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

   Insert an File
Check here to include your profile signature.
Check here to subscribe to this topic.
    

T O P I C    R E V I E W
Jpez1432 Posted - Dec 01 2004 : 08:59:22 AM
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.
3   L A T E S T    R E P L I E S    (Newest First)
Eric Coleman Posted - Dec 02 2004 : 12:17:26 AM
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.
Jpez1432 Posted - Dec 01 2004 : 6:05:49 PM
like in doom, when you walk into a wall at a angle it lets you slide against it.
sdw Posted - Dec 01 2004 : 5:04:09 PM
Can you explain what you mean by "slide along the line"?

VBGamer © Go To Top Of Page
This page was generated in 0.05 seconds. Snitz Forums 2000

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