# MrAccident

Member

128

232 Neutral

• Rank
Member
1. ## Jumping problems in C++

Quote:Original post by ExcessNeo Mr. Accident Acceleration is constant yes being -9.81m/s/s however you can't just decide to end acceleration mid-air until you have reached terminal velocity, rip-off's example is a bit strange though having another look. But either way, gravitational acceleration should be subtracted from velocity, not the player's acceleration. If you subtract 9.81m/s^2 from the player's acceleration every frame, it is no longer an acceleration constant, but a jerk constant. Not counting air resistance, gravitation produces a constant acceleration, so the player's acceleration should not change unless another force acts upon them (for example, the ground). For simple jumping physics, air resistance isn't going to be a significant factor. But if you did want to add it to your model, you wouldn't do it by subtracting g from the object's acceleration every frame; for a decent approximation you could introduce an opposing force that scales linearly with the velocity of the object, and just add that to the gravitational acceleration vector to determine the object's acceleration at any given time.
2. ## Jumping problems in C++

It sounds like what you've been doing is just trying to "code as you go," which is definitely going to be a confusing and frustrating experience if you don't already have a good idea of how your system is going to work. It's always a good idea to clearly think out your approach and create a design before you start writing code. rip-off made a very good suggestion when he said you should decouple movement from input. What he meant (and illustrated with his code sample) is that you should give the player object physical properties like velocity and acceleration, instead of just directly changing the position of the player whenever the movement keys are pressed. Then, each frame you can add the player's velocity to their current position to make them move. Also each frame, subtract your gravitational acceleration constant from their upward velocity (unless they're already on the ground). The movement keys can then work by changing the player's velocity: if the left or right keys are pressed, the player should have a corresponding negative or positive X velocity. When the spacebar is pressed, you can just give the player an initial upward velocity, and your gravitational acceleration will take care of the rest. Adjusting the initial jump velocity will give you different jumping heights.
3. ## Jumping problems in C++

So, what exactly is the problem you're having? Code snippets alone in this case aren't very enlightening: it would help if you'd explain your reasoning and your approach to the problem, as well as precisely what difficulties you've encountered. In what way are you using the "gravity" field? What is your conceptual model of player movement and physics? How did you try to incorporate jumping into that model before, and how did it fail? Basically, try to explain your whole situation a bit better, and it will be much easier for others to give you advice. [smile] EDIT: Ah, ninja'd. [lol] rip-off: any particular reason in your code it's subtracting gravitational acceleration from the player's acceleration every frame? Seems to me that once the player is in the air, the acceleration should be constant, since (in this basic example anyway) there are no other forces besides gravity acting on the player. For simplicity, I'd probably treat jumping as an instantaneous impulse giving an initial vertical velocity.
4. ## script for flash & C ++

Well, I don't do a lot of Flash stuff, but to my understanding, there's so little in common between the way games are written in Flash with ActionScript and the way games are usually written in C that it seems like achieving any kind of script commonality would be more trouble than it's worth. Maybe I'm misinterpreting your question? It seems to me that if you want your game to run both on the web and on the desktop, you could just distribute a downloadable copy of your Flash game, without having to rewrite anything. You can also package Flash files as self-running executables if that's what you'd prefer.
5. ## Unity Game state: serializing cooperative threads?

I've been thinking lately about ways to serialize game state, and I began thinking about how this would work in a game using a script interface that supports cooperative threads. (Coroutines, or generators, or what have you.) Let's take a simple example and suppose we have a map with an object moving around it whose motion is controlled by a coroutine. Then say we want to save the game at some point, and be able to resume it later with the object picking up exactly where it left off. It seems to me that one option is to build a system in which cooperative threads can be serialized while they are suspended, and then revived at a later time with the same locals and resume point. The game could have a scheduler that manages all cooperative threads, and can serialize them to and from persistent memory along with all the other data that makes up the game's current state. In this way, the behavior of objects within the game can be scripted with cooperative threads without worrying about what happens if a save-and-reload occurs in the middle of their lifetimes; as long as the all the objects are brought back in the correct state, and the scheduler restores itself to the same state as before, things will work smoothly. Another option would be to just serialize your entire VM state, though that seems like an unnecessarily heavy operation. My question is, is this a feasible solution in general? Does anybody actually do this, or is it generally better to restructure your game so that all cooperative threads will terminate before game state is saved? (Or else make script writers operate under the assumption that their threads are not part of the game's persistent state.) I did a bit of searching, and found this thread, which suggests that Lua is capable of doing what I describe, but I'm still curious as to whether this seems like a good idea or not. It seems like it would have a few obvious benefits, including making it possible to write simple, natural entity scripts while basically hiding most serialization from the script interface. It would involve a bit more work on the back end, but I'm not seeing any significant reasons that this wouldn't be a worthwhile option. Any thoughts?
6. ## Making Squirrel more instance-oriented? (Prototypes, JavaScript, etc.)

I posted this over on the squirrel-lang.org forum earlier today, but since things seem to move fairly slowly over there, I figured I'd post it here as well to maybe get some quicker feedback. [grin] I'm in the process of designing a simple scriptable game engine. I was originally thinking about using Spidermonkey JavaScript for the project, but when I found Squirrel I was immediately tempted to switch. For my purposes Squirrel has a lot of advantages: it's simpler, much more lightweight, and not encumbered by the extras and security considerations that a browser-targeted system like Spidermonkey includes by necessity. Supporting both generators and cooperative thread semantics is a nice plus. It also looks like embedding is a bit easier than it is with Spidermonkey. However, I'm very used to JavaScript's prototypes and instance-based OOP, and compared to this Squirrel's object semantics seem almost arbitrarily rigid. In JavaScript, all objects are highly mutable; you can dynamically add new properties and methods. Using prototype objects, you can add behaviors to entire families of objects. (On the Squirrel forum, aeyr suggested something like this for Squirrel in this post in the "Roadmap to 3.x" thread.) In Squirrel, the class system is fairly strict. Classes can be modified dynamically, but only before any instances have been created. Class instances themselves cannot have new slots added to them. This enforces the "contractual" interface we would expect from an object based on its class membership, but for a long-time fan of JavaScript, it makes objects seem rigid and inflexible, not quite what a dynamic language should be, especially since Squirrel is duck-typed already. Why enforce class contracts in a duck-typed language? Basically, my thinking is that if Squirrel were just a little bit more like javascript, it would be perfect. I don't know if Alberto Demichelis would think these would be productive changes to the language any time soon, so I was thinking I would try to make some changes for myself and see how they work out. I was thinking of a system in which classes serve only as templates for object construction, and every object's interface would be mutable. Maybe with some prototyping semantics from JavaScript tossed in. I just wanted to get a bit of feedback on if this sounds like it might be a worthwhile idea, or if maybe I would be better off sticking with JavaScript or learning to accept the rigid classes of Squirrel. I have a bit of experience writing compilers, but not a whole lot on the practical side, so I'm not completely familiar with the sort of obstacles I might encounter. Any advice would be appreciated. [smile]
7. ## Saving drawn objects

Quote:Original post by EasilyConfusedI assume MFC provides a virtual function or something you can use to respond to WM_PAINT under the hood. Yep; just override OnPaint() in your CDialog-derived class, and create a CPaintDC in that method to do your drawing. Then all your drawing code will be run every time the window is invalidated.
8. ## How Many More Students Must Die Before The United States Gets Real About Gun Control?

Quote:Original post by LessBread No. It means that people have the right to keep and bear arms in expectation of being called by the State government to serve in "a well regulated militia" as needed to provide for the common defense. If there is no expectation of being called to serve in the state militia, there is no justification for keeping or bearing arms. If anything, the 2nd amendment and 18th century practice would indicate that every able bodied male should be drafted into state militias. Earlier in the discussion I stipulated National Guard, but in as much as the National Guard is a part of the Army, such a draft wouldn't jibe with the 2nd amendment. If the common defense of security were the only purpose of a citizen militia, I would not have much of a problem with this interpretation, though I still think it is wishful thinking to inject a connotation of purposeful restriction into a statement of justification. But you are ignoring the other purpose of an armed citizenry, which many of the founders were quite unambiguous about in their writings. Quote:I think there is a lot we can do to reduce the number of "violent freak outs" - from better mental health care onwards. I think throwing our hands up and saying there's nothing we can do only guarantees that such massacres will happen again and again and again as they have for decades now. I don't think I phrased that quite as well as I intended - I meant that attempting to restrict or prohibit dangerous articles can have only a very limited effect on such crimes of insanity, since there are plenty of opportunities for a truly unhinged person to cause mayhem that we can never eliminate. I certainly did not mean that there's "nothing we can do" There is much that can be done, and trying to make sure mentally unstable people cannot purchase firearms is a good start, but it won't be enough. Quote:Some things more important than our lives? That sounds to me like a high fallutin' cop-out along the lines of: "Freedom's untidy, and free people are free to make mistakes and commit crimes and do bad things." It's not a cop-out; it's just my belief. I'm genuinely grateful to all who have sacrificed in the name of liberty, and I feel it is my duty to be willing to do the same. Where do you get the idea that I think people are "free" to commit crimes? Quote:Would you tell the parents that lost children in this incident that gun rights are more important than their children's lives? I doubt that you would. Please. This is an entirely emotional argument. I would never presume to say anything so callous to a grieving family, and I'm not going to try to put a "price" on any one life. But the simple fact is that if guns exist in our society, people will die by them. We should do what we can to reduce the toll, but I believe that the right to bear arms is fundamentally important and that some price will have to be paid. I'm well aware that it might just be me that winds up being gunned down by a psycho someday, but it's a risk I'm willing to take. EDIT: And what's all this about charging the guy who sold Seung-Hui his gun? If it can be shown that he violated state or federal law when he made the sale, then certainly charges will be appropriate. But from what I've heard, the purchase was quite legal when it occurred. Have I been misinformed?
9. ## How Many More Students Must Die Before The United States Gets Real About Gun Control?

Quote:Original post by LessBread The issue of gun control has been raised in reaction to the event. That makes raising the issue reactive (ie. characterized by reaction) but not reactionary (ie. opposing political or social change). Well, I stand corrected. Quote:By protecting military weapons that ruling lends credence to the "National Guard" interpretation of the 2nd amendment - despite the 2004 DoJ memo to the contrary. Why? The Miller case particularly concerned individual possession and transportation, though considerations relating to this fact were never made part of the Court's discussion. The fact that the Supreme Court indicated that the Second Amendment protected firearms with current military application simply does not speak to the issue of collective rights versus individual rights. You could just as well argue that the Miller decision implicitly supported individual rights, since the contrary interpretation was not used to rule against Miller instead! It seems pretty clear to me that the intent behind the Second Amendment was to ensure the ability of a citizen militia to exist outside of the control of the government. If it were under the control of the government, it would be unable to serve the purpose that the founders wanted to prepare for, even while they were doing their best to prepare against it. Quote:The prefatory clause and the operative clause are both two clauses, so there are four clauses all together: "A well regulated militia" and "being necessary to the security of a free State" and "the right of the People to keep and bear arms" and "shall not be infringed." I don't have the time or inclination to read all 107 pages of the memo - and I seriously doubt that you did either when you asserted that it's arguments were sound and damning. Perhaps there's a specific item in the memo that you'd like to discuss? Otherwise, go fish! [smile] Is there a particular reason you think the division of those subclauses is relevant? I don't quite see how it aids any analysis to further separate the prefatory and operative sections of the amendment. And actually, I did read the memorandum in its entirety last year when I first learned of its existence. If you'd like to discuss specific points: - What makes you think the prefatory declaration places restriction on the operative assertion that "the right of the People to keep and bear arms shall not be infringed"? - Do you think that "the right of the People" in the amendment means "the right of the Government", and if so, what support do you have for this interpretation? Quote:Quote:Original post by MrAccident To a certain extent, I agree, which is why I think better education is very important as well. However, I feel that the top priority (as regards gun control laws specifically) is to keep firearms available to responsible, law-abiding citizens. Requiring training and permits for handgun ownership seems to me like a good way to attempt to screen out those who are not responsible. Annual training and permits are good, but it would seem that psych screenings are needed as well (especially in light of ptsd in veterans). That said, I think we focus too much on handgun owners and not enough on handgun makers. I don't mean responsible companies (ie. those with household names), I mean the fly-by-nighters that make cheap guns and dump them into our cities. It seems that the right of gun makers to turn a buck far too often out strips the rights of gun violence victims. Well, we're more or less in agreement about handguns then. Don't mistake me, though - I doubt very much that there's all a whole lot we can do to prevent incidents like this one, gun control or no. Cracking down on gang activity and cheap illegally sold guns may certainly help reduce street crime (and, IMHO, more well-trained CCW holders helps here as well), but I frankly don't think there's anything we can do to stop the occasional deranged individual from snapping and killing a bunch of people. If not handguns, a hunting rifle. If not a rifle, a bomb. If not a bomb, an automobile driven into a crowd. There are far too many ways to wreak havoc - the only hope we have is to try to pay more attention to troubled individuals, and hopefully get them the help they need before they snap. I guess, bottom line, I can sum up my feelings thusly: Life is risky. Freedom is not safe. We should all attempt to provide reasonable protections for our safety and prosperity, without forgetting that there are some things more important than our lives.
10. ## How Many More Students Must Die Before The United States Gets Real About Gun Control?

Quote:Original post by LessBreadSo you don't know what the word reactionary means either? Apparently not. I meant that raising the issue of gun control was a reaction specifically to the event. If "reactionary" doesn't describe something that is primarily in reaction to something else, then I confess ignorance on that point. Quote:#1 United States v. Miller The Supreme Court declared that no conflict between the NFA and the Second Amendment had been established,writing ... we cannot say that the Second Amendment guarantees the right to keep and bear such an instrument[sawed off shotgun]. The National Firearms Act imposes a statutory excise tax on the sale of machine guns among other weapons. The transfer tax of \$200 placed on the transfer of firearms controlled by the Act was roughly equivalent to five months' salary in 1934. That was exactly my point; in deciding against Miller, the Court stated its opinion that the Second Amendment specifically protected military weapons. Hence: handguns and shotguns, not so protected; assault rifles and .50-cal, protected. I happen to disagree with the court's narrow interpretation of what constitutes military small arms, but for what it's worth it's the closest thing we have to a Supreme Court interpretation of the second amendment. Quote:#2 Anything coming from this corrupt DoJ isn't worth the paper it's written on. What's damned is this DoJ and it's crooked AG. For all we know, the NRA wrote that memorandum for the DoJ. I did point out that the memorandum has no legal status - however, having read it carefully, I believe the argument presented is valid. Regardless of how much I despise the Attorney General (and in large part, recent actions of the DOJ itself), the memorandum seems like a convincing argument to me. Maybe you'd like to raise some specific issue with it that could be debated? Quote:#3 10 U.S.C. 311 is there to facilitate military conscription. From U.S. v. Miller: These show plainly enough that the Militia comprised all males physically capable of acting in concert for the common defense. 'A body of citizens enrolled for military discipline.' And further, that ordinarily when called for service these men were expected to appear bearing arms supplied by themselves and of the kind in common use at the time. So when you're drafted, don't forget to bring your shotgun with you to the service examination! [smile] Will do! [smile] Quote:The reactionary measure is to continue business as usual (and that's what it would be a continuation of business) regarding guns and to instead clampdown on the first amendment, which is what shifting the blame to "cultural problems" amounts to. It seems to me that not focusing on guns amounts to sticking our heads in the sand. After each of these massacres we don't seriously focus on guns and soon enough another massacre and another massacre and another massacre happens. As I keep saying, asserting that the problem is cultural is to admit that our culture does not produce enough sufficiently mature adults to allow any random citizen to own guns. To a certain extent, I agree, which is why I think better education is very important as well. However, I feel that the top priority (as regards gun control laws specifically) is to keep firearms available to responsible, law-abiding citizens. Requiring training and permits for handgun ownership seems to me like a good way to attempt to screen out those who are not responsible. Quote:I think it depends on what you mean by crime. Here's a list of incidents: Criminal Use of the 50 Caliber Sniper Rifle. Many of these are technical crimes, that is, a suspect was arrested for some other crime and these guns turned up during a search of their vehicles or homes. However, note the case of Donin Wright: In February of 2004, Donin Wright of Kansas City, Missouri, lured police officers, paramedics, and firefighters to his home where he shot at them with several guns including a Barrett 50 caliber sniper rifle. Also note the case of Albert Petrosky: Petrosky, who was known to his friends as "50-cal Al," fired all four weapons, including the 50 caliber rifle, during his murderous rampage. And let's not forget this: Branch Davidian cult members at a compound in Waco, Texas, fired 50 caliber sniper rifles at federal ATF agents during their initial gun battle on February 28, 1993. And lastly, the account of an attack on an armored truck in Chamblee, Georgia in 1992 where the two guards were shot with a Barrett. Ah, thank you for bringing that to my attention; I hadn't been aware of those incidents. Still, .50 caliber rifles are so infrequently (and relatively ineffectively) used in crime, I think they're hardly worth even batting an eye at. More effective and well-enforced handgun laws will go a very, very long way towards curbing gun violence, so I would say that should be the focus of any reasonable gun control effort. Also, it simply must be pointed out that .50 caliber is the most effective round for hunting dangerous game like squirrels. (...Actually, I'm morally opposed to hunting, but I just can't say the phrase "exploding squirrels" in my head without giggling. Tee-hee! [grin])