Need help with physics+wireframe cube. (Page 1) ● SmileBASIC Source Forums

Register
• #4 ✎ 167 Mariominer First Day Joined on the very first day of SmileBASIC Source Website Promoted Page My page was promoted on SmileBASIC Source! Achievements Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength The way that I lower the required variables to store if you have a lot of objects is by using trigonometry. Instead of X velocity and Y velocity, I use a direction and magnitude. So instead of Y_velocity=1 it would be more like DIR=90:MAG=1. The most difficult part is getting added force to be added to this number. What I do is I keep a variable for X added and Y added, so I can know how much force goes in all the directions, including the inertia from the previous direction and magnitude. Then I use ATAN to find the direction that it goes in, while using basic distance formula to find the magnitude that the force goes in. If you want to have just one IF statement for collisions, I would recommend storing each object's position in an array, then using a FOR statement to find it.```FOR I=0 TO LEN(X)-1 IF I==OBJECT THEN CONTINUE 'Object being the object that you're trying to find collision for IF X[OBJECT]==X[I] AND Y[OBJECT]==Y[I] THEN 'handle the collision NEXT```You can work with larger radiuses by detecting distance, or work with longer objects in just one way by detecting longer ranges. You can use these ideas for lots of different physics, but obviously the more you add, the harder it will be to control. You can also add other variables depending on the physics you add (so if you add friction, texture would be important) Posted