View Single Post
  #25  
Old 11-19-2011, 06:24 AM
Tricxta Tricxta is offline
The Muffin Man
Tricxta's Avatar
Join Date: Oct 2010
Location: Australia
Posts: 563
Tricxta is just really niceTricxta is just really nice
Quote:
Originally Posted by Gunderak View Post
I know how to detect if there on a wall, but how would I handle it?
I have tried reversing the players movement which is this.
PHP Code:
    player.-= sin(this.angle) * this.speed;
    
player.-= cos(this.angle) * this.speed
But that doesn't work.
I think I'm in way over my head.
That won't reverse the direction in which the player moves, instead do what chris said and just add pi to the existing angle.

Quote:
Originally Posted by cbk1994 View Post
You're not keeping it clean, you're just overcomplicating it and adding more work for the engine. It takes longer for a scripter to read and understand your code than it does mine.
I meant variable wise, you're going to keep on adding onto your angle which will eventually become quite a large number if used for a while. Also while you do have a valid point I'm sure one extra mod and multiplication operator doesn't effect performance to the point where you'd notice on any machine. What if I wanted to see what was going on in the script and I had some huge messy number as the angle, it'd be pretty ugly to work with. Also by including mod and multiplication the angle can work with other formulas if you choose.

Also for those who don't know % is the mod operator. It works by spitting out the remainder of 2 given numbers. Eg:6%4=2, 6%5=1, 11%10=1
Reply With Quote