Charging a shot

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
rambo16125
Gnoblar
Posts: 4
Joined: Mon May 12, 2014 2:37 pm

Charging a shot

Post by rambo16125 »

Not sure if this is the right place to post, but i'm gonna give it a shot.

My assignment requires me to create a FPS shooter, and 1 of the fuction is to allows the user to shoot a ball.
It also allows the user to charge the shot by holding down the mouse button.

I need some guide on doing the charged shot.
What I had in mind is to implement a for-loop, and while the button down state is true, the force will keep adding until the user release the button and the shot is fired.
But so far I couldn't achieved that with the for-loop.

Anyone can guide me on this? I am a bit lost here and the google search have not been too kind to me.

I am using Ogre + Bullet physics.
User avatar
shadowfeign
Goblin
Posts: 213
Joined: Mon Jan 26, 2009 11:51 pm
x 15

Re: Charging a shot

Post by shadowfeign »

Any kind of loop will just pause the rendering. What you want to do is increment a variable every frame by some value multiplied by timeSinceLastFrame.
rambo16125
Gnoblar
Posts: 4
Joined: Mon May 12, 2014 2:37 pm

Re: Charging a shot

Post by rambo16125 »

Oh wow, didn't know loop will pause the rendering.

I also need to implement a type of machine gun, but now that loop pauses the rendering, how do I go about firing multiple shots while holding down the mouse button?
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 139

Re: Charging a shot

Post by c6burns »

Perhaps you need to put in some time analyzing the samples and tutorials provided with Ogre. You should be performing your actions in a FrameListener. The wiki tutorial framework and tutorials/samples show how to set this up and make use of it in a variety of scenarios. FrameListener::frameRenderingQueued is a generally good place to take action. It provides you with a FrameEvent (http://www.ogre3d.org/docs/api/1.9/stru ... Event.html) you can use to determine how long it's been since the last frame. This is what shadowfeign is talking about with timeSinceLastFrame.

For an example machinegun, if the mouse is down when you hit this callback, then the machine gun needs to start or continue firing. If the mouse is up then it needs to stop or continue not to fire.

For an example charged shot, keep a variable of how charged it is, but use timeSinceLastFrame as a multiplier so that the gun charges at a speed independent of the game's framerate (eg. slower computers charge the same speed as faster ones)
rambo16125
Gnoblar
Posts: 4
Joined: Mon May 12, 2014 2:37 pm

Re: Charging a shot

Post by rambo16125 »

thanks for the tips!
User avatar
lingfors
Hobgoblin
Posts: 525
Joined: Mon Apr 02, 2007 12:18 am
Location: Sweden
x 79

Re: Charging a shot

Post by lingfors »

State machines are pretty good to use for these kind of things...
Post Reply