Attaching a sword to the camera

One of my students wants to make a battle scene in the Colosseum. Basically the player would enter the forum and battle gladiators, large animals etc. We have been experimenting to try to figure it out but thus far we’ve been unsuccessful. We’ve tried attaching the camera to the eyes of a battling knight and Roman soldier but when you press play, the view is disorienting. We’ve also tried to parent a lone sword with the camera but unfortunately the camera doesn’t move. Is there an way to do this?

Here is the link to his CoSpace. CoSpaces Edu :: Three Worlds. The Colosseum is in scene 5.

Hi @TechWarriors,
I have an example with animation and switching weapons here:

Feel free to remix it and, if need be, simplify it. The concept is that you parent the sword to the camera instead, that way the camera still moves as it would normally and the sword automatically follows it.

1 Like

Luc, I don’t know what I would do without you. Your Vampire Hunter game was the inspiration for my student. I did look through the code of the game but it is pretty complicated and was unable to isolate its location. I’ll take a look through the test. Thank you Luc.

1 Like

Hi Luc,
I am experimenting with the code. I noticed you have code to swing the weapon when pressing a specific key. How do you get the edge of the weapon to swing as opposed to the full weapon to spin?

Hi @TechWarriors,

Bets way is to add a dummy object like an invisible cube to the base of the handle as an axis to rotate, then simply rotate the sword.

I’ve attached here an example with some comments to explain some things, including how to make the animation feel more lifelike by rotating the sword towards the player first, imagine hitting a hamer we don’t rotate the hammer to the nail immediately but instead rotate it towards our selves to create leeway.

Also yellow event blocks do not need to be put in a forever loop or run parralel loop; They become active once the code reads it and will stay that way until you tell the computer otherwise, essentially they have a “forever loop” around them by default.

Hope this helps!

1 Like