Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
nightbird0

Realistic shell ejection JS

Question

Hi guys , i want help on how to make realistic shell ejection in javascript, i know i rarely use javascript since im a c# guy but since this will be added on OMA's weaponScriptNew then i need it on JS..

 

Here is my current one :

Please login or register to see this code.

my problem, i want to be MORE realistic and add some smooth rotation on it ... 

 

Any help would be appreciate  :d

Edited by nightbird0

Share this post


Link to post
Share on other sites

29 answers to this question

Recommended Posts

  • 0

You could use a Lerp or Slerp to change the rotation smoothly as it flies away, I'm not exactly sure how to do it in js, and I can't write an example as I'm on my phone, but that's probably a good way to do it

Share this post


Link to post
Share on other sites

  • 0

You can actually put that code into two lines instead of three. You just need to setup a vector3.

to smoothly rotate something create a new script and put this in the bullet shell prefab. Paste this in:

Please login or register to see this code. Add some slerp or lerp if needed.

Share this post


Link to post
Share on other sites
  • 0

Try using a Random Range of force to make it look more realistic because everybullet doesnt have the same force applied.

Share this post


Link to post
Share on other sites
  • 0

thank you guys, i think now is pretty good, here are the final scripts

Please login or register to see this code. Please login or register to see this code.

9J96Q8k.pngeWEaeuc.png

Edited by nightbird0

Share this post


Link to post
Share on other sites
  • 0

I recommend using Random RANGE as with random.value(0.0-1.0) there may be no force at all!

Please login or register to see this code.
  • Like 1

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

yeah .. i noticed that sometimes one of the two directions have 0 force :d... i'm going to fix it ... thanks man :d

Share this post


Link to post
Share on other sites
  • 0

Only use Random.value if you want it for 0 - (certain number). Images aren't showing up on my laptop so I will have to restart it :|

Share this post


Link to post
Share on other sites
  • 0

Random.Value is ranging from 0.0 to 1.0 while in Random.Range you assign your own range.

  • Like 1

Share this post


Link to post
Share on other sites
  • 0

I know but what I meant was Random.value * (certain number). Really sorry if the post was confusing, I am stupid sometimes :P

 

I also like using Random.Range too

Share this post


Link to post
Share on other sites
  • 0

:d thank you again patriot :)

 

here is a video guys from the result  (I add a script that destroy the shell after a short  amount of time, just to prevent lag ... is that right ? )

 

Edited by nightbird0

Share this post


Link to post
Share on other sites
  • 0

There is a script for the bullet holes that destroys them after some secs. Use it and set it in 3-4 secs. Or you could possible make a script fade their alpha color to make it smoother or even add them to meshes as projectors to make it more realistic.

Share this post


Link to post
Share on other sites
  • 0

ok, i want to ask you , my bulletholes are flashing on the wall and looks really annoying , (BTW i meant that the shell have the script that destroy itself :d )

Share this post


Link to post
Share on other sites
  • 0

Alright...to fix the flashing bullet holes increase the offset of the decals.

Share this post


Link to post
Share on other sites
  • 0

my problem is when press right key("D") shell ejction is on left direction and when press left key ("A") bullet ejction is on right direction.how solve when press right key bullet ejection in only right side.please help

Edited by GamezZz

Share this post


Link to post
Share on other sites
  • 0

Instantiate the shell prefab first and to eject it you can apply force. Then a script on the instantiated object keeps rotating it in a direction.

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

You asked how it works, and so I told you how it works. No one is going to make scripts for you just like that. It is right in front of your eyes, just use it.

Share this post


Link to post
Share on other sites
  • 0

Just attach a particle system, play with the values and have it use a bullet shell mesh and call ParticleSystem.emit(1); when you shoot. No need to manually code the whole system

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...