Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Gun swaying + lighting

Author
Message
JJJ0han
17
Years of Service
User Offline
Joined: 4th Oct 2007
Location: Brisbane, Australia
Posted: 21st Oct 2007 10:39 Edited at: 21st Oct 2007 10:40
I'm sure there's various gun swaying and bobbing codes, but I haven't found any that worked for me. I've been trying to make my own but that hasn't worked much either.

Well, basically, like the title says, I want my gun to sway. Currently its just slapped onto the screen.

I don't necessarily want the actual camera or player to bob up and down, but that'd be nice if that's possible too. I'm just mainly focusing on swaying the gun for a bit more realism and functionality to my game.

Well here's the rotation code that I've got, and I'm just wondering if it's possible to implement the swaying into this or if I'm going to have to use a different way to rotate the player around?

Variables
I'll just quickly list the variables since you might need them.

sensitivity# = 3
GunObj = 3
the player = 2

Mouse Look - Where I want the sway effect
The mouse look is a very simple 2 line code. It's all I need, but I just still don't see how to make the weapon sway with it.


The code that slaps the gun on the screen


The gun is hidden at first because it is loaded during a loading screen. I did "show" the object somewhere I just can't find the code right now.

Oh and, as the title also states, I want the gun that I'm using to change the light. Is that possible with a DBO level from 3d world studio? I tried placing actual DBP lights which I had just added to the code but none of these seem to allow the light on my gun to change. It just stays bright. The HDR shader I have changes the tint on it a little but that's about it.

Again, yeah the mouse movement code is a little simplistic, I was actually surprised my self when I went to salvage it from my project.
The Samurai
20
Years of Service
User Offline
Joined: 28th Jul 2004
Location: San Angelo, Tx
Posted: 6th Nov 2007 02:10
Have you tried using a sin function? It makes a wave like line that can be used for swaying an object. Just make sure you loop it to where it doesn't sway right off the screen!

vorconan
18
Years of Service
User Offline
Joined: 4th Nov 2006
Location: Wales
Posted: 7th Nov 2007 00:53
Samurai has a good idea, we just need to explain that point a bit more.

Sin waves are basically points plotted on a graph and are linked by curves, the points are found by finding the sin value of a number between 0-360, this is what you should end up with.



You may be able to use this to reposition the gun, and creating a good swaying effect, it may not be the easiest method but it never hurts to touch up on this sort of maths in programming.



Ellatica
17
Years of Service
User Offline
Joined: 6th May 2007
Location:
Posted: 22nd Nov 2007 03:06
i found this code a while back and thought you might be interested.


first off you would make variables towards movements,speed,angles,gun position. after in loop you start with movment and how it will affect your swaying/bobbing. next there is the else statments wich are being implemented for the decrease/increase of bobbing. after is the code to implement swaying using sin. it needs to see how much you have moved the mouse in what direction, speed of the mouse moving and sways according to the related variables. after is position camera/player.

if you need any help email me.
all credits to Joseph Thomson for the code.

JJJ0han
17
Years of Service
User Offline
Joined: 4th Oct 2007
Location: Brisbane, Australia
Posted: 24th Nov 2007 10:23
That's funny, I found that just a few days before you posted it. It seems to be working great!

Login to post a reply

Server time is: 2024-11-25 09:46:29
Your offset time is: 2024-11-25 09:46:29