• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a faction for Warcraft 3 and enter Hive's 19th Techtree Contest: Co-Op Commanders! Click here to enter!
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 21st Texturing Contest: Upgrade is now concluded, time to vote for your favourite set of icons! Click here to vote!

Deflection

Status
Not open for further replies.
Level 20
Joined
Jul 6, 2009
Messages
1,885
I'm making a movement system and i can't solve a problem.
I'm trying to make an object deflect off edge of a rectangle. (Coordinates of vertices are known; rectangle isn't static and is, in most cases, rotated.)
attachment.php

The main problem is i can't get the angle of perpendicular on rectangle edge (The red line).
Each time i move the object, i check if the object's coordinates are within the rectangle, if they are, a collision occurs and i need to change the object's movement vector, but i need the perpendicular's angle for that. Anyone knows how to retrieve it?
+rep for help.
 

Attachments

  • untitled.jpg
    untitled.jpg
    10.8 KB · Views: 152
Since the perpendicular line will create a 90 degree angle, you can make a check of (1) 90 - (Angle between points), where points = Position of vehicle and Position of the moving object. Then, when the collision occurs (define offset limit), you will move the object in x1 + 500 * Cos (Facing of Vehicle - (1)) and y1 + 500 * Sin (Facing of Vehicle - (1)).
I am bored of making rad conversions to check the result, but it looks like it's a possible way.
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
But that, as far as i know, wouldn't work for rotated rectangle. However, i've got an idea - i can loop through each side of rectangle and see if intersects the object's movement and since i'm looping through sides, i have their angles thus the perpendiculars too.
Thanks for efforts though.
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
The key in this case is the vehicle's facing. You can control pretty much everything if you have an accurate facing and you do have, since you are manipulating and simulating driving, so the rectangle's rotation is or should be (for easier handling) facing-dependent.
Lol...i'm so dumb D:
Should have thought of that; yeah, i'll do it like that, thanks ;D
 
search for "reflection vector"
you will need the normal vector of the surface and the incoming vector v1
the reflection vector will be 2*(v1 dot normal)*normal-v1 (or the same *-1, not sure)
the surface normal should be normalized

if you want to do this with angles you can use "the angle of incidence equals the angle of reflection" (wikipedia article is nice)

and you probably asked that or something very similar before (or someone else)

your problem is solved already but I thought you could be interested in this
 
Status
Not open for further replies.
Top