Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 24 Apr 2010
Offline Last Active Private

#5259221 Excuse me < How do I create Models/Objects for my game?

Posted by Khatharr on 26 October 2015 - 07:48 PM

Blender is actually on par with the ridiculously expensive competitors, and personally I felt it has better documentation than Max. Krita is another Photoshop alternative I've been looking at lately. It takes a little getting used to but it has some interesting tools. You can get it for free if you agree to GPL rules, so it depends on what you're doing with it.

#5259219 The wrong way to count lines of code

Posted by Khatharr on 26 October 2015 - 07:22 PM

[server hamsters duplicated my message. It wasn't my fault. promise.]


We all know you were just trying to sneak in an extra Line of Convo.

#5258930 Confusion with smart pointers

Posted by Khatharr on 24 October 2015 - 11:21 PM


So, I read that you cannot have two std::unique_ptr point to same object.


Technically you can:

#include <memory>

int main()
   int* foo = new int;
   std::unique_ptr<int> fooPtr1(foo);
   std::unique_ptr<int> fooPtr2(foo); // Double-delete bug!

So always be careful (and consistent!) with how you mix and match your smart pointers with your regular pointers!



Better yet, use std::make_unique() instead of naked 'new'.

#include <iostream>
#include <memory>
#include <random>

struct Foo {
  Foo(int baz) : bar(baz) {}
  int bar;

int main() {
  std::mt19937 generator(std::random_device{}());
  std::uniform_int_distribution<int> distribution(0, 100);

  auto thing = std::make_unique<Foo>(distribution(generator));
  std::cout << "The number is: " << thing->bar << ".\n\n";
  system("pause > nul");

#5258929 Disable Colliders

Posted by Khatharr on 24 October 2015 - 11:16 PM

public class DisableCollider : MonoBehaviour
	Collider myCollider;
	void Start() {
		myCollider = GetComponent<Collider>();
	void Update (){
		if(Input.GetKeyDown(KeyCode.E)) {
			myCollider.enabled = !myCollider.enabled;

When you're using GetComponent<> to fetch something, consider fetching it once in Start() and storing it to avoid the cost of fetching it every frame. Input.GetKey() is true as long as the key is held, but Input.GetKeyDown() is only true on the frame that the key was first pressed, so you can use it to make things happen only once per key-press.

#5256102 What's the best system on which to learn ASM?

Posted by Khatharr on 07 October 2015 - 04:25 PM

Ah, I getcha.

#5255935 What's the best system on which to learn ASM?

Posted by Khatharr on 06 October 2015 - 08:14 PM


I'll throw in a vote for x86 through VS. In addition to what's been said, it gives you the opportunity to fiddle with C/C++ and see how the stack and function calls work.

This is quite true, and I guess you could target DOSbox if worst came to worst.





Desktop PCs run x86 natively.

#5255924 What's the best system on which to learn ASM?

Posted by Khatharr on 06 October 2015 - 06:51 PM

I'll throw in a vote for x86 through VS. In addition to what's been said, it gives you the opportunity to fiddle with C/C++ and see how the stack and function calls work. Also, I think that if you just pick something accessible and jump right in then you'll get the basics down and you can expand from there in whatever direction you please.

#5252327 Attribution problems on Github

Posted by Khatharr on 15 September 2015 - 04:22 AM

If you post something on GitHub or any other public repository, include a license agreement that clearly states terms of use. If someone violates that agreement then you have grounds to take action by contacting GitHub or the authorities. Alternatively, you can use a private repo. I think they're like $7 USD a month or cheaper by the year.

#5251838 Is there a language like Python but without the tab requirement?

Posted by Khatharr on 12 September 2015 - 02:04 AM



but aligning code is pretty silly as well IMO.


Umm... what?


l0calh05st obviously writes all of his programs on a single line, didn't you know? It saves disk space.



It runs faster too, because the CPU doesn't have to keep scrolling down.

#5251538 Hello! Where To Start C++

Posted by Khatharr on 10 September 2015 - 08:34 AM

If you're already comfortable with C# then you may want to look at learning MonoGame or SFML.Net instead of switching langauges.


If your interest really is in C++ then you may want to check out this SO post:




As for when to learn 2D programming, opinions vary, but if you're already decent with some language then just pick up a 2D library and start going through its tutorials. You'll run into problems during this, but you can ask for help and keep on learning. Once you're comfortable with a 2D library then you can start to make simple games like Pong, Breakout, and Asteroids in order to learn progressively about game development in general.

#5251534 How to make a simple 3D battlemap to use in RTS game

Posted by Khatharr on 10 September 2015 - 08:11 AM

In this case it sounds like your question is really about the use of VPython, including loading and positioning assets.


If you edit your original post to something like "Loading and positioning objects in VPython" I think you can change the thread title and possibly attract people who know more about VPython. You may want to also provide more specific information about what you're doing. You're talking about "flat ground" as opposed to terrain, but you're also asking about how to load a "map", which can mean different things depending on context. Is this a texture that you want to apply to the ground?

#5250944 [SFML] [C++] Bullet angle problem

Posted by Khatharr on 06 September 2015 - 11:01 PM

Create a simple struct to represent each bullet. It should store all the information about the bullet that it represents, including position, velocity, and life timer. When you update the bullets you add the velocity to the position in order to get the new position, and you decrement the life timer. When drawing the scene, just loop through the bullets and draw each one at its current position using the same graphic (this will improve graphics performance, since SFML does not re-bind the texture if it's the same as the previously used one).


Example pseudocode:


* if mouse button is down

** add a bullet to the vector (may want to add a firing delay or whatever)

** set its position and life timer

** set the velocity to be the direction toward the mouse times the speed it should travel at

* end "if"


* for each bullet in the vector

** decrement life timer

** if life timer > 0

*** position = position + velocity

** end "if"

* end "for"


* iterate vector in reverse

** if life timer <= 0

*** remove the bullet

** end "if"

* end "loop"


// in drawing section

* for each bullet in the vector

** if life timer > 0

*** draw the bullet at its current position

** end "if"

* end "for"


Alternatively, you can create an array with a length indicating the maximum number of bullets that can exist at one time, then skip updating and drawing bullets whose life is expired. When creating a bullet in this case you would simply move through the array looking for a position with an expired bullet. Remember to initialize the array such that all of the bullets start out as expired.

#5246347 PeekMessage changed in Windows 10?

Posted by Khatharr on 13 August 2015 - 07:34 PM

I initially encountered this behavior in Win7 when I found that I couldn't catch certain messages outside of the proc. (It looks like you may be trying to do the same thing I was trying to do, actually.)

#5245213 Simple Math question about angle. How can you find the end coordinates of a r...

Posted by Khatharr on 09 August 2015 - 05:01 AM

Keep in mind, if you are doing this for a game... this is going to be horrendously slow. Your best bet would be to use a matrix.

This is pretty close to what a rotation matrix does, really. If you're only doing a z-axis rotation of a 2D point you may as well just extract the math.


Rotation of theta degrees around z-axis (this is exactly what a 2D rotation matrix would do, but without the matrix):

x = (x * cos(theta)) - (y * sin(theta))

y = (x * sin(theta)) + (y * cos(theta))


Matrices are handy because they allow multiple transforms to be concatenated into a single transform and then applied to several vertices without needing to repeat any of the work.


For example, if you want to rotate a lot of points by 30 degrees then your matrix is:

[cos(30), sin(30)]

[sin(30), -cos(30)]


Which is

[0.866, 0.5]

[0.5, -0.866]


Then the vector mul works out to:

x = (x * 0.866) + (y * 0.5)

y = (x * 0.5) - (y * 0.866)


For any 2D point/vector.

#5245210 Velocity and deltatime confusion

Posted by Khatharr on 09 August 2015 - 04:30 AM

If you're wanting to do a cheap simulation of drag then it should be applied as a force in the opposite direction of velocity and scaled by velocity.

float dragFactor = 0.5f;
vec drag = velocity * -dragFactor;
vec netForce = velocity + drag;
position += netForce * dt;

Note that realistic drag physics is a little more involved, but still generates a force to be added to the net force on the entity. In this case 0.5 is a bit steep. It's going to bring you to a screeching halt.


Incidentally, v -= v * 0.5 is equivalent to v *= 0.5.